Skip to content

Instantly share code, notes, and snippets.

@stan
Forked from elijahmanor/jquery.filterbydata.js
Created July 20, 2011 01:19
Show Gist options
  • Save stan/1094138 to your computer and use it in GitHub Desktop.
Save stan/1094138 to your computer and use it in GitHub Desktop.
filterByData jQuery Plugin
// http://www.elijahmanor.com/2011/07/filterbydata-jquery-plugin.html
// https://gist.github.com/1048942
(function($) {
/* by Elijah Manor with collaboration from Doug Neiner
* Filter results by html5 data attributes either at
* design or at runtime
*
* Usages:
* $( "p" ).filterByData( "mytype" );
* $( "p" ).filterByData( "mytype, "mydata" );
*/
$.fn.filterByData = function( type, value ) {
return this.filter( function() {
var $this = $( this );
return value != null ? $this.data( type ) === value : $this.data( type ) != null
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment