Bug Tracker

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#9499 closed bug (fixed)

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.

Change History (5)

comment:1 Changed 6 years ago by theallan

jsFiddle example: http://jsfiddle.net/EvcfC/

Possibly similar to bug #6914.

comment:2 Changed 6 years ago by rwaldron

  • Component changed from unfiled to attributes
  • Owner set to rwaldron
  • Priority changed from undecided to high
  • Status changed from new to assigned

@ajpiano and I agree: addClass should not allow you to add the same class twice

comment:3 Changed 5 years ago by timmywil

  • Milestone changed from 1.next to 1.7
  • Owner changed from rwaldron to timmywil

comment:4 Changed 5 years ago by timmywil

  • Milestone changed from 1.7 to 1.6.2

comment:5 Changed 5 years ago by timmywil

  • Resolution set to fixed
  • Status changed from assigned to closed

Check classes passed for duplicates. Fixes #9499.

Changeset: db437be6e31c924aade13bb719f9facc122b3d9c

Note: See TracTickets for help on using tickets.