/ Published in: jQuery
Select the specified option for alle html selects as jQuery.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Sets for all matched elements (DOM selected as jQuery) the option as selected. * * @param jQuery A jQuery object. Eg. $('select') or $(selector). * @param option The optionvalue that will be selected. Eg. a number or string. * * @requires jQuery * @author pogosheep < [email protected] > */ function setActiveSelectOption(jQuery, option) { $.each(jQuery.children(), function(index, element) { if ($(element).val() === option) { $(element).attr('selected', 'selected'); } else { $(element).removeAttr('selected'); } }); }