Side navigation
#9499 closed bug (fixed)
Opened June 02, 2011 06:05PM UTC
Closed June 08, 2011 01:03AM UTC
Last modified March 08, 2012 10:10PM UTC
removeClass will only remove the first instance of a class
Reported by: | theallan | Owned by: | timmywil |
---|---|---|---|
Priority: | high | Milestone: | 1.6.2 |
Component: | attributes | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I've just been debugging an issue in my software where adding and removing classes with addClass and removeClass were doing something slightly odd. I realised that while addClass will add multiple instances of a class to an element (fair enough, I've asked it to do that), removeClass will only remove the first instance of a class. I would have expected it to remove all instances of the given class (although this could be an incorrect assumption on my part). For example
$("#test1").addClass("disabled disabled");
alert("test1 class after addClass ='"+$("#test1").attr("class")+"'");
$("#test1").removeClass("disabled");
alert("test1 class after removeClass ='"+$("#test1").attr("class")+"'");
The first alert will give "disabled disabled" while the second alert gives "disabled". I had anticipated it just being an empty string.
Attachments (0)
Change History (5)
Changed June 02, 2011 06:08PM UTC by comment:1
Changed June 02, 2011 06:12PM UTC by comment:2
component: | unfiled → attributes |
---|---|
owner: | → rwaldron |
priority: | undecided → high |
status: | new → assigned |
@ajpiano and I agree: addClass should not allow you to add the same class twice
Changed June 08, 2011 12:53AM UTC by comment:3
milestone: | 1.next → 1.7 |
---|---|
owner: | rwaldron → timmywil |
Changed June 08, 2011 01:00AM UTC by comment:4
milestone: | 1.7 → 1.6.2 |
---|
jsFiddle example: http://jsfiddle.net/EvcfC/
Possibly similar to bug #6914.