Return to Snippet

Revision: 30122
at August 8, 2010 07:35 by pogosheep


Updated Code
/**
 * 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');
            }
        });
    }

Revision: 30121
at August 8, 2010 07:34 by pogosheep


Updated Code
/**
 * Sets for all matched elements (DOM selected as jQuery) the option as selected.
 *
 * @param jQuery The select as jQuery object.
 * @param option the Option Value that will be selected.
 *
 * @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');
            }
        });
    }

Revision: 30120
at August 8, 2010 07:33 by pogosheep


Updated Code
/**
     * Sets for all matched elements (DOM selected as jQuery) the option as selected.
     *
     * @param jQuery The select as jQuery object.
     * @param option the Option Value that will be selected.
     *
     * @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');
            }
        });
    }

Revision: 30119
at August 8, 2010 07:31 by pogosheep


Initial Code
function setActiveSelectOption(jQuery, option) {
        $.each(jQuery.children(), function(index, element) {
            if ($(element).val() === option) {
                $(element).attr('selected', 'selected');
            }
            else {
                $(element).removeAttr('selected');
            }
        });
    }

Initial URL


Initial Description
Select the specified option for alle html selects as jQuery.

Initial Title
Select the specified option for alle html selects as jQuery.

Initial Tags
javascript, jquery, function

Initial Language
jQuery