Posted By

inreflection7 on 05/31/12


Tagged

jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

hurcy
symsec


Extend jQuery selector types


 / Published in: JavaScript
 

Extend jQuery :selector types

Ex: $("input:text") $("input:email")

  1. $.extend($.expr[':'], {
  2. email: function(em) {
  3. return $(em).attr("type") === "email";
  4. }
  5. });
  6.  
  7. // ':textall' jQuery pseudo-selector for all text input types
  8. // source: http://markdalgleish.com/2011/05/jquery-selector-for-html5-input-types/
  9.  
  10. (function($) {
  11. var types = 'text search number email datetime datetime-local date '
  12. + 'month week time tel url color range'.split(' '),
  13. len = types.length;
  14. $.expr[':']['textall'] = function(elem) {
  15. var type = elem.getAttribute('type');
  16. for (var i = 0; i < len; i++) {
  17. if (type === types[i]) {
  18. return true;
  19. }
  20. }
  21. return false;
  22. };
  23. })(jQuery);

Report this snippet  

You need to login to post a comment.