diff --git a/src/attributes.js b/src/attributes.js index 1e0e79f4b..c862f38c6 100644 --- a/src/attributes.js +++ b/src/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; } } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index bc3eb25f5..578fd71a9 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -1063,5 +1063,5 @@ test("contents().hasClass() returns correct values", function() { $contents = $div.contents(); ok( $contents.hasClass("foo"), "Found 'foo' in $contents" ); - ok( $contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" ); + ok( !$contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" ); });