I have a jquery code below where an option which has been selected from a drop down menu is removed from the drop down menu:
var selectedOption = jQuery("#modulesDrop option:selected");
selectedOption.remove();
But before I perform the remove, I want to add the content from the drop down menu into a select box, but the problem is that I don’t seem to know how to do this. I tried the code below but all that did was remove the option from the drop down menu as above and did not add the option into the select box:
var selectedOption = jQuery("#modulesDrop option:selected");
selectedOption.appendTo("#moduleExistForm");
selectedOption.remove();
You don’t need to call
remove()becauseappendTo()automatically detaches the element from its original parent then appends it on the new element that you specify:Here’s the fiddle:
http://jsfiddle.net/8MAny/