Skip to content

Instantly share code, notes, and snippets.

@robcowie
robcowie / optgroup_filter.js
Created March 31, 2012 19:41
Filter option elements by optgroup based on value of a second select element
$.fn.filterGroups = function( options ) {
var settings = $.extend( {}, options);
return this.each(function(){
var $select = $(this);
// Clone the optgroups to data, then remove them from dom
$select.data('fg-original-groups', $select.find('optgroup').clone()).children('optgroup').remove();
$(settings.groupSelector).change(function(){