Skip to content
Permalink
Browse files

Merge pull request #419 from rwldrn/9630

Unit tests assert that .contents().hasClass() works as expected. Fixes #9630
  • Loading branch information...
dmethvin committed Aug 4, 2011
2 parents 5417a2c + bb17025 commit 6a3395afcdb958a25f9a7cba3e544fe10d4d123a
Showing with 11 additions and 1 deletion.
  1. +1 −1 src/attributes.js
  2. +10 −0 test/unit/attributes.js
@@ -146,7 +146,7 @@ jQuery.fn.extend({
hasClass: function( selector ) {
var className = " " + selector + " ";
for ( var i = 0, l = this.length; i < l; i++ ) {
if ( (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
return true;
}
}
@@ -1062,3 +1062,13 @@ test("addClass, removeClass, hasClass", function() {
jq.removeClass("class4");
ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
});

test("contents().hasClass() returns correct values", function() {
expect(2);

var $div = jQuery("<div><span class='foo'></span><!-- comment -->text</div>"),
$contents = $div.contents();

ok( $contents.hasClass("foo"), "Found 'foo' in $contents" );
ok( !$contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" );
});

0 comments on commit 6a3395a

Please sign in to comment.
You can’t perform that action at this time.