Skip to content

Instantly share code, notes, and snippets.

@danheberden
Created June 27, 2011 14:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danheberden/1048942 to your computer and use it in GitHub Desktop.
Save danheberden/1048942 to your computer and use it in GitHub Desktop.
findData plugin - search by data-KEY=VALUE on and in current jQ collection
/*
* by Dan Heberden / 2011
* demo at http://jsfiddle.net/danheberden/VjKMY/
* made just for Elijah Manor
* e.g.
* $( 'div' ).findData( 'theDataKey', 'theValue' );
*
* will search in the divs and their children
*/
(function( $ ){
$.fn.findData = function( key, value ) {
var sel = '[data-' + key + '="' + value + '"]';
return this.find( sel ).add( this.filter( sel ) );
}
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment