Thursday, 15 September 2011

jquery - Is there a way to remove optgroup without destroying the code? -



jquery - Is there a way to remove optgroup without destroying the code? -

all attempting edit old code, had made alternative group, i'd take away. can't css because it's using chosen plugin.

function flavorchooser (title, item) { var title = 'hidden'; var optgroup = jquery('<optgroup display="' + title + '"/>'); jquery.each(item, function(sub_title, sub_item) { if (typeof sub_item[0] !== "undefined") { var opt = jquery('<option value="' + sub_item[0] + '" data-store-locator-value="' + sub_item[0] + '">' + sub_title + '</option>'); optgroup.prepend(opt); } }); // console.log('chozen '); // jquery('.chzn-container .chzn-results .group-result').css('display', 'none'); homecoming optgroup;

}

this works remove of optgroup children of given select element:

markup:

<select id="myselect"> <optgroup label="mygroup"></optgroup> <option>option</option> <option>option</option> <option>option</option> <option>option</option> <optgroup label="mygroup2"></optgroup> <option>option</option> <option>option</option> <option>option</option> </select>

jquery:

$(function () { $("#myselect").children().remove("optgroup"); });

jsfiddle: http://jsfiddle.net/frjeq/

jquery drop-down-menu

No comments:

Post a Comment