dbj* filterByCSS

QUnit usage from http://jsfiddle.net/elijahmanor/fqJmu/light/

by dbjdbj

HTML

<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<h1 id="qunit-header"></h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div id="testbed" class="testbed">
</div>
 </div>

CSS

body { margin: 10px; padding: 0; background-color:grey; }
.testbed { position:absolute; display:none; }

JavaScript

(function($) {
/* 
 * GPL/MIT (c) 2013 by DBJDBJ 
 * inspired by Elijah Manor $.fn.filterByData()
 * Filter results by CSS properties 
 *
 * Usages:
 * $( "p" ).filterByCSS( "left" );
 * $( "p" ).filterByCSS( "left", "10px" );
 */
$.fn.filterByCSS = function( css_prop, value ) {
    return this.filter( function() {
        var $this = $( this );

        return value != null ?
            $this.css( css_prop ) === value :
            $this.css( css_prop ) != null;
    });
};
})(jQuery);


  var $fixture = $( "#qunit-fixture" );
    
        
    test("should find one 'testbed' div for display:'none'", 
       function (){
            var $d = $("div").filterByCSS("display","none") ;
            ok($d[0]);
            ok(1 == $d.length);
        });
        
        test("should find 2 div's where 'left' is 'auto', since this is default value for the css property 'left'",
           function () {
            var $d = $("div").filterByCSS("left","auto") ;
            ok(2 == $d.length);
        });