Skip to content

Instantly share code, notes, and snippets.

@og-shawn-crigger
Created October 9, 2012 21:00
Show Gist options
  • Save og-shawn-crigger/3861403 to your computer and use it in GitHub Desktop.
Save og-shawn-crigger/3861403 to your computer and use it in GitHub Desktop.
jQuery extension to grab all data from a element
/**
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