(function ($, undefined){ '$:nomunge'; var selectColorize = 'selectColorize', event_name = 'change.' + selectColorize, style = 'style', color = 'color', backgroundColor = 'backgroundColor'; $.fn[selectColorize] = function (destroy){ var that = this.unbind(event_name); that.each(function (){ var select = $(this), select_color = select.css(color), select_backgroundColor = select.css(backgroundColor); if (destroy !== undefined) { select.find('option').andSelf().each(function (){ var elem = $(this), data = elem.data(selectColorize); data && elem[data[style]? 'attr': 'removeAttr'](style, data[style]); elem.removeData(selectColorize); } ); } else if (!select.data(selectColorize)) { select.data(selectColorize, { style: select.attr(style)} ); select.find('option').each(function (){ var option = $(this), opt_style = this.style; option.data(selectColorize, { style: option.attr(style)} ); opt_style[color] || option.css(color, select_color); opt_style[backgroundColor] || option.css(backgroundColor, select_backgroundColor); } ); } } ); if (destroy === undefined) { that.bind(event_name, function (){ var select = $(this), option = select.find('option:selected'), css = { } , bg_color; if (option.length) { css[color] = option.css(color); bg_color = option.css(backgroundColor); css[backgroundColor] = bg_color === 'rgb(255, 255, 255)'? '#fffffe': bg_color; select.css(css); } } ).triggerHandler(event_name); } return that; } ; } )(jQuery);