From 27e5052a7bd9e8d0af1a94ec2ad0c2c2317c3b50 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 21 Jun 2011 14:04:06 -0400 Subject: [PATCH 1/2] Assert that .contents().hasClass() works as expected. Fixes #9630 --- test/unit/attributes.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 4716e5b53..bc3eb25f5 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -1055,3 +1055,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("
text
"), + $contents = $div.contents(); + + ok( $contents.hasClass("foo"), "Found 'foo' in $contents" ); + ok( $contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" ); +}); From bb1702518e43e88c31922af8b0f3bd4aa29017d2 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Wed, 22 Jun 2011 08:50:44 -0400 Subject: [PATCH 2/2] 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)" ); });