How can I clone dropdown list(combobox) with selected option?
jquery .clone method is not working in firefox for selected option.
I have a div having different controls. I have to copy entire div to a variable something like this
var $orginalDiv = $('#myDiv');
var $clonedDiv = $orginalDiv.clone();
$clonedDiv.find('select').each(function() {
....Something do here for assigning selected options from original div ..
});
Let me know how can we get it done and it must be worked in FireFox.
var $orginalDiv = $('#myDiv');
var $clonedDiv = $orginalDiv.clone();
//get original selects into a jq object
var $originalSelects = $orginalDiv.find('select');
$clonedDiv.find('select').each(function(index, item) {
//set new select to value of old select
$(item).val( $originalSelects.eq(index).val() );
});
Try it here at jsfiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With