Last active
December 21, 2015 02:08
-
-
Save scy/6232291 to your computer and use it in GitHub Desktop.
A simple :data(key) selector for jQuery
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
// jQuery UI has a :data selector. I wanted to have it without including jQuery UI. | |
// To find out how all of this works, read the Sizzle documentation: | |
// https://github.com/jquery/sizzle/wiki/Sizzle-Documentation | |
// Thanks to @_Tomalak for inspiring me to check this out. | |
jQuery.expr.pseudos.data = jQuery.expr.createPseudo(function (key) { | |
return function (el) { | |
return !!jQuery.data(el, key); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I always used the following
But yours seems more convenient.