Custom jQuery Pseudo-Class :css() Selector Expression


/ Published in: jQuery
Save to your folder(s)

adapted from the fantastic „Learning jQuery 1.3“ book

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


Copy this code and paste it in your HTML
  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. });

URL: http://jsbin.com/ojora

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.