Created
April 27, 2010 08:07
-
-
Save padolsey/380481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Idea from http://dbaron.org/log/20100424-any | |
jQuery.expr[':'].any = function(el, i, match) { | |
return jQuery.find.matches(match[3], [el]).length > 0; | |
}; | |
jQuery('body :any(div, form) p'); // Same as jQuery('body div p, body form p') | |
jQuery('div:any(.foo,.bar)'); // Same as jQuery('div.foo, div.bar') |
A different approach — http://twitter.com/padolsey/status/119790781417537536:
$.expr[':'].matches=(function(_){return function(el,i,m){return!!_(m[3]||'*',[el])[0];};}($.find.matches)); // CSS4 :matches selector for jQ
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good point, @beverloo. The jQuery selector syntax has helped me better understand CSS. Syntactic sugar isn't enough of a benefit to justify moving away from the standard.