Extend jQuery selector types

[javascript]
$.extend($.expr[‘:’], {
email: function(em) {
return $(em).attr("type") === "email";
}
});

// ‘:textall’ jQuery pseudo-selector for all text input types
// source: http://markdalgleish.com/2011/05/jquery-selector-for-html5-input-types/

(function($) {
var types = ‘text search number email datetime datetime-local date ‘
+ ‘month week time tel url color range’.split(‘ ‘),
len = types.length;
$.expr[‘:’][‘textall’] = function(elem) {
var type = elem.getAttribute(‘type’);
for (var i = 0; i < len; i++) {
if (type === types[i]) {
return true;
}
}
return false;
};
})(jQuery);
[/javascript]

Leave a Reply