Skip to content

Instantly share code, notes, and snippets.

@luanmuniz
Created February 19, 2014 14:20
Show Gist options
  • Save luanmuniz/9093056 to your computer and use it in GitHub Desktop.
Save luanmuniz/9093056 to your computer and use it in GitHub Desktop.
Custom select
(function($){
'use strict';
$.fn.extend({
customStyle: function(){
var html = $('html');
if (!html.hasClass('ie') || (html.hasClass('ie') && !html.hasClass('lt-ie7'))) {
return this.each(function () {
var t = $(this),
currentSelectedText = t.find(':selected').text(),
classes = t.attr('class');
if(!t.parent().hasClass('selectcustom')){
t.wrap('<span class="selectcustom ' + classes + '" />');
t.before('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">' + currentSelectedText + '</span><span class="customStyleIcon"></span></span>');
t.css({'opacity': '0'}).change(function(){
var ts = $(this);
ts.parent().addClass('changed').find('.customStyleSelectBoxInner').text(ts.find(':selected').text());
});
}
});
}
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment