Skip to content

Instantly share code, notes, and snippets.

@corymartin
Created December 25, 2011 06:42
Show Gist options
  • Select an option

  • Save corymartin/1518824 to your computer and use it in GitHub Desktop.

Select an option

Save corymartin/1518824 to your computer and use it in GitHub Desktop.
jQuery pseudo selectors for HTML5 input types
//
// Adds jQuery Pseudo Selectors for HTML5 input types.
//
// Example:
// HTML:
// <input type="email" name="user_email">
// jQuery:
// $(':email');
//
//
// Pseudo Selectors:
// :color
// :date
// :datetime
// :datetime-local
// :email
// :month
// :number
// :range
// :search
// :tel
// :time
// :url
// :week
//
(function($) {
var types = 'color date datetime datetime-local email month number range search tel time url week'.split(' ');
$.each(types, function(i, type) {
$.expr[':'][type] = function(el) {
return el.nodeName.toUpperCase() === 'INPUT' && el.type === type;
};
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment