Created
July 4, 2013 16:37
-
-
Save jayde/5929003 to your computer and use it in GitHub Desktop.
Check to see if a <select> has an empty selection/no value.
This file contains hidden or 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
// Check to see if a <select> has an empty selection/no value | |
$.fn.checkEmptySelection = function() { | |
var emptyClass = 'noselection'; | |
$(this).each(function() { | |
if( $(this).val() == emptySelection ) { | |
$(this).addClass(emptyClass); | |
} | |
}); | |
$(this).on('blur change', function() { | |
if( $(this).val() == emptySelection ){ | |
$(this).addClass(emptyClass); | |
} | |
if( $(this).val() != emptySelection ){ | |
$(this).removeClass(emptyClass); | |
} | |
}); | |
$(this).on('focus', function() { | |
$(this).removeClass('noselection'); | |
}); | |
} | |
$('select').checkEmptySelection(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment