Skip to content

Instantly share code, notes, and snippets.

@dciccale
Created August 6, 2011 19:42
Show Gist options
  • Save dciccale/1129678 to your computer and use it in GitHub Desktop.
Save dciccale/1129678 to your computer and use it in GitHub Desktop.
Extend jQuery form selectors expressions with HTML5 input types
jQuery.extend(jQuery.expr[':'], {
email: function(a) {
return a.type&&a.type=='email';
},
url: function(a) {
return a.type&&a.type=='url';
},
search: function(a) {
return a.type&&a.type=='search';
},
tel: function(a) {
return a.type&&a.type=='tel';
},
datetime: function(a) {
return a.type&&a.type=='datetime';
},
date: function(a) {
return a.type&&a.type=='date';
},
month: function(a) {
return a.type&&a.type=='month';
},
week: function(a) {
return a.type&&a.type=='week';
},
time: function(a) {
return a.type&&a.type=='time';
},
datetimelocal: function(a) {
return a.type&&a.type=='datetime-local';
},
number: function(a) {
return a.type&&a.type=='number';
},
range: function(a) {
return a.type&&a.type=='range';
},
color: function(a) {
return a.type&&a.type=='color';
}
});
** IMPORTANT **
This will only work on modern browsers that supports these new input types, if not they will be treated as "text" types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment