Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#3825 closed enhancement (fixed)

enhance .toggleClass

Reported by: cloudream Owned by: brandon
Priority: minor Milestone: 1.4
Component: core Version: 1.2.6
Keywords: Cc:
Blocked by: Blocking:

Description

  1. remove/re-add all original CSS class

implement: save original class to $.data on elements

Case: el: <span class="a b" />

step#1:$(el).toggleClass(); -save "a b" to $.data(this,"originalClass"), then remove "a b" class on this element. step#2:$(el).toggleClass(); -restore $.data(this,"originalClass")(if exists) to this element.

And with boolean: step#1:$(el).toggleClass(false); -save "a b" to $.data(this,"originalClass"), then remove "a b" class on this element.

step#1:$(el).toggleClass(true); -restore $.data(this,"originalClass")(if exists) to this element.

2.handle multi-class without boolean. use .toggleClass("c b") instead of .toggleClass("c").toggleClass("b")

implement: split className string before pass it to $.className[add/ remove], and handle each one separately

Case: el: <span class="a b" />

step#1:$(el).toggleClass("b c"); -remove class "b" and add class "c" on this element. step#2:$(el).toggleClass("b c"); -remove class "c" and add class "b" on this element.

Change History (4)

comment:1 Changed 7 years ago by brandon

  • Owner set to brandon

comment:2 Changed 7 years ago by brandon

  • Milestone changed from 1.3 to 1.3.3
  • Resolution set to fixed
  • Status changed from new to closed

Added in r6332.

comment:3 Changed 5 years ago by jitter

  • Keywords needsDocs added

comment:4 Changed 5 years ago by kswedberg

  • Keywords needsDocs removed

added documentation at http://api.jquery.com/toggleClass/

Note: See TracTickets for help on using tickets.