Created
January 8, 2015 15:28
-
-
Save DougSisk/f69a063e9ae960889c28 to your computer and use it in GitHub Desktop.
jQuery Dropdown Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<div class="select"> | |
<div class="selected"></div> | |
<select> | |
<option>Option</option> | |
</select> | |
</div> | |
*/ | |
(function($) { | |
$.fn.dropdown = function() { | |
return this.each(function() { | |
var top = $(this); | |
var select = $(this).find('select'); | |
var selected = $(this).find('.selected'); | |
selected.text(select.find('option:selected').text()); | |
if(select.val()) | |
$(this).addClass('has-value'); | |
select.on('change', function(){ | |
var currentVal = $(this).find('option:selected').text(); | |
selected.text(currentVal); | |
top.addClass('has-value'); | |
top.removeClass('has-error'); | |
}); | |
}); | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment