From bb1702518e43e88c31922af8b0f3bd4aa29017d2 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Wed, 22 Jun 2011 08:50:44 -0400 Subject: [PATCH] Filter hasClass by nodeType 1; Fixes #9630 --- src/attributes.js | 2 +- test/unit/attributes.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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)" ); }); -- 2.39.5