Filter hasClass by nodeType 1; Fixes #9630

This commit is contained in:
rwldrn 2011-06-22 08:50:44 -04:00
parent 27e5052a7b
commit bb1702518e
2 changed files with 2 additions and 2 deletions

View File

@ -146,7 +146,7 @@ jQuery.fn.extend({
hasClass: function( selector ) { hasClass: function( selector ) {
var className = " " + selector + " "; var className = " " + selector + " ";
for ( var i = 0, l = this.length; i < l; i++ ) { 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; return true;
} }
} }

View File

@ -1063,5 +1063,5 @@ test("contents().hasClass() returns correct values", function() {
$contents = $div.contents(); $contents = $div.contents();
ok( $contents.hasClass("foo"), "Found 'foo' in $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)" );
}); });