Bug Tracker

Opened 14 years ago

Closed 14 years ago

#3711 closed bug (wontfix)

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.

Change History (1)

comment:1 Changed 14 years ago by flesler

Cc: cFreed added
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.

Note: See TracTickets for help on using tickets.