Skip to main content

Bug Tracker

Side navigation

#9630 closed bug (fixed)

Opened June 21, 2011 07:18AM UTC

Closed August 04, 2011 09:33PM UTC

Last modified August 26, 2011 02:50AM UTC

foo.contents().hasClass() returns incorrect value

Reported by: olov.lassus Owned by: rwaldron
Priority: low Milestone: 1.6.3
Component: attributes Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:
Description

hasClass("undefined") returns true incorrectly for elements that do no have the className property (as opposed to having it set to ""), such as text and comment nodes.

Verified with Chrome 12 and Firefox 5.

Pull request for patch and test case to follow.

Attachments (0)
Change History (12)

Changed June 21, 2011 07:34AM UTC by olov.lassus comment:1

Changed June 21, 2011 03:30PM UTC by rwaldron comment:2

component: unfiledattributes
priority: undecidedlow
resolution: → worksforme
status: newclosed

Changed June 21, 2011 03:42PM UTC by olov.lassus comment:3

As I demonstrated in the test case included in the pull request this is working as expected for DIV nodes (I included that expectation for completeness) but not for text and comment nodes.

The jsFiddle test you linked to just shows that this is a non-issue for DIV nodes, doesn't it?

Changed June 21, 2011 04:01PM UTC by rwaldron comment:4

Right, but the add|removeClass methods only care about nodeType 1 ( https://developer.mozilla.org/en/nodeType )

Updated:

http://jsfiddle.net/rwaldron/D5QgV/

Changed June 21, 2011 05:34PM UTC by olov.lassus comment:5

That's fine and I see the nodeType guards in addClass/removeClass, but what about hasClass? Should one be able to rely on jQuery("div").contents().hasClass or not? The existing hasClass implementation contains no guards and is used in that manner in your existing unit tests.

http://jsfiddle.net/olov/sMceh/ is reduced to make it clearer

Changed June 21, 2011 05:56PM UTC by rwaldron comment:6

resolution: worksforme
status: closedreopened
summary: hasClass("undefined") returns incorrect value for text and comment nodesfoo.contents().hasClass() returns incorrect value

Changed June 21, 2011 06:00PM UTC by rwaldron comment:7

owner: → rwaldron
status: reopenedassigned

Changed June 21, 2011 06:06PM UTC by rwaldron comment:8

Changed June 22, 2011 06:15AM UTC by olov.lassus comment:9

_comment0: Do you consider the patch in my pull request adequate for fixing this issue?1308750358834541

Do you consider the patch in my pull request adequate for fixing this issue?

''edit: https://github.com/jquery/jquery/pull/419 is now updated with a correct test case and the bugfix so landing that will fix this ticket''

Changed July 12, 2011 04:59PM UTC by ajpiano comment:10

milestone: 1.next1.7

Changed August 04, 2011 09:33PM UTC by Dave Methvin comment:11

resolution: → fixed
status: assignedclosed

Merge pull request #419 from rwldrn/9630

Unit tests assert that .contents().hasClass() works as expected. Fixes #9630

Changeset: 6a3395afcdb958a25f9a7cba3e544fe10d4d123a

Changed August 26, 2011 02:50AM UTC by dmethvin comment:12

milestone: 1.71.6.3