Created
October 9, 2012 21:00
-
-
Save og-shawn-crigger/3861403 to your computer and use it in GitHub Desktop.
jQuery extension to grab all data from a element
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
/** | |
This is stolen from jQueryUI 1.9 but works well by itself, it will add a Pseudo selector to select all data from a element | |
usage is | |
var data = $(".selector:data()"); | |
console.log(data); | |
*/ | |
$.extend( $.expr[ ":" ], { | |
data: $.expr.createPseudo ? | |
$.expr.createPseudo(function( dataName ) { | |
return function( elem ) { | |
return !!$.data( elem, dataName ); | |
}; | |
}) : | |
// support: jQuery <1.8 | |
function( elem, i, match ) { | |
return !!$.data( elem, match[ 3 ] ); | |
}, | |
}); | |
$("body:data()"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment