copying options of select into another select
I have 2 html-selects, one as source, the other as target. I want to copy the source-options to the target.
#sel_rel > source
#sel_new_after_rel > target
- function openFormAddRel(){
- generateFieldset("Release hinzufügen", "reg_edit", "form_add_rel");
- var root=$("#form_add_rel");
- root.append("<input id='inp_rel_add_name'></input>");
- root.append(" einordnen <select id='sel_new_after_rel'></select>");
- $("#sel_new_after_rel").append("<option id='sel_new_after_rel_0' name='0'>als ersten</option>");
- var sellist=$("#sel_rel").children();
- var id;
- var newitem;
- $.each(sellist, function(i,item) {
- if (i!=0) {
- newitem=item;
- $("#sel_new_after_rel").append(newitem);
- id=$("#sel_new_after_rel").children(":last").attr("id");
- newid=id.replace(/sel_rel_/g,"");
- $("#sel_new_after_rel").children(":last").attr("id","sel_new_after_rel_"+newid);
- $("#sel_new_after_rel_"+newid).prepend("nach ");
- }
- });
- root.append("<button id='but_rel_add_name'>Hinzufügen</button>");
- $("#but_rel_add_name").attr("onClick","relAddName()");
- }
While appending the option-elements to the targetselect the original option-elements disappear (exactly at step of line 13). This is unwanted behaviour. How can I prevent this?