Reputation: 33
Need to clone select box from previous one ( ie, add select box 'n' number of time from the previous one ) But when I added each time, all the previously selected options should not be available in the cloned select box list.
$('.field_select_box_list').each(function(){
$(this).find('option:selected').remove();
});
This code removes the parent select boxes selected option too.. but I want remain them to have the selected option.
any help.
Upvotes: 1
Views: 1542
Reputation: 137
I think you need use one select_box original, hidden it. Then you can remove with select_box second not hidden or add more element from select_box original.
Upvotes: 0
Reputation: 15802
Your clone code can just do something like
$('el').clone().find('option:selected').remove().end()
The .end()
causes the selector to return to being $('el')
rather than the filtered option:selected
selector, so you can continue running things like .appendTo()
etc without needing to break the chain.
Upvotes: 4