Bug Tracker

Modify

Ticket #3711 (closed bug: wontfix)

Opened 5 years ago

Last modified 5 years ago

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

comment:1 Changed 5 years ago by flesler

  • Cc cFreed added
  • Resolution set to wontfix
  • Status changed from new to closed
  • Component changed from unfilled to core

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.