Posted By

cfleschhut on 08/18/09


Tagged

plugin jquery Expression selector


Versions (?)

Custom jQuery Pseudo-Class :css() Selector Expression


 / Published in: jQuery
 

URL: http://jsbin.com/ojora

adapted from the fantastic „Learning jQuery 1.3“ book

http://www.packtpub.com/learning-jquery-1.3/book

  1. jQuery.extend(jQuery.expr[":"], {
  2. "css": function(element, index, matches, set) {
  3. var parts = /([\w-]+)\s*([<>=]+)\s*(\d+)/.exec(matches[3]);
  4. var value = parseFloat(jQuery(element).css(parts[1]));
  5. switch (parts[2]) {
  6. case "<":
  7. return value < parseInt(parts[3]);
  8. break;
  9. case "<=":
  10. return value <= parseInt(parts[3]);
  11. break;
  12. case "=":
  13. case "==":
  14. return value == parseInt(parts[3]);
  15. break;
  16. case ">=":
  17. return value >= parseInt(parts[3]);
  18. break;
  19. case ">":
  20. return value > parseInt(parts[3]);
  21. break;
  22. }
  23. }
  24. });

Report this snippet  

You need to login to post a comment.