damsean102
7/19/2011 - 4:51 AM

filterByData jQuery Plugin

filterByData jQuery Plugin

(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);