Skip to content

Instantly share code, notes, and snippets.

@TexRx
Forked from elijahmanor/jquery.filterbydata.js
Created November 27, 2013 06:49
Show Gist options
  • Save TexRx/7671625 to your computer and use it in GitHub Desktop.
Save TexRx/7671625 to your computer and use it in GitHub Desktop.
(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