Created
November 4, 2012 20:57
-
-
Save madflow/4013745 to your computer and use it in GitHub Desktop.
jQuery pseudo selector
This file contains 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
<input | |
id="val1" | |
type="text" | |
data-validate-required | |
data-validate-minlength="3" | |
data-validate-email /> | |
<input /> | |
<script> | |
jQuery.expr.pseudos.attr = $.expr.createPseudo(function(arg) { | |
var regexp = new RegExp(arg); | |
return function(elem) { | |
for(var i = 0; i < elem.attributes.length; i++) { | |
var attr = elem.attributes[i]; | |
if(regexp.test(attr.name)) { | |
return true; | |
} | |
} | |
return false; | |
}; | |
}); | |
console.log($(":attr(^data-)")); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment