Skip to main content

Bug Tracker

Side navigation

#3711 closed bug (wontfix)

Opened December 12, 2008 04:01PM UTC

Closed December 16, 2008 12:41PM UTC

hasClass() ALWAYS returns true when argument is empty or begins with space(s)

Reported by: cFreed Owned by: flesler
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: cFreed
Blocked by: Blocking:
Description

Found in jQuery 1.2.6, tested under Firefox 3.0.4 with Firebug 1.2.1.

Choose an existing <htmlTag id="someId" ...>

In the Firebug console, control that this tag has not a certain class, e.g.:

$("#someId").hasClass("foo"); returns false

Now try prepending a space before 'foo':

$("#someId").hasClass(" foo"); returns true!!!

The same happens with more prepending spaces and/or \\t, and also with hasClass("").

CAUTION: as a non-english, I don't understand the "Needs" list options, so I left it to its default value, which is not a significant choice.

Attachments (0)
Change History (1)

Changed December 16, 2008 12:41PM UTC by flesler comment:1

cc: → cFreed
component: unfilledcore
resolution: → wontfix
status: newclosed

hasClass doesn't support classes with spaces.

For that you need to use either '[class*=foo]' or a filter function that uses $.className.has.

This might be fixed once Sizzle is implemented.