Ticket #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 | |
| Blocking: | Blocked by: |
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.