javascript - jQuery clone select list remove selected -
i have button cloning element on page each time user clicks it. duplicating select list them take option.
however, cloning whole element including alternative selected of new ones appended have default value dont want.
globallocales = $("<div />").append($('[name=localeid]:first').clone()).html(); $('select').select2(); is there way can remove selected alternative during cloning process doesn't carry on new element?
i tried using .removeprop('selected') in append .prop('selected',false); didn't work me
one way prepare proble select nonexistent value:
$("<div />").append($('[name=localeid]:first').clone().val(-1)).html(); or can find selected alternative , remove selected attribute:
$("<div />").append($('[name=localeid]:first').clone() .find(':selected').removeattr('selected').end()).html(); but little clumsy.
javascript jquery
No comments:
Post a Comment