Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 6 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.

Attachments (1)

toggleClass.diff (2.6 KB) - added by iraebrasil 8 years ago.
unit test and core implementation proposal for #3825 enhancement (forgot one cleanup)

Download all attachments as: .zip

Change History (5)

Changed 8 years ago by iraebrasil

Attachment: toggleClass.diff added

unit test and core implementation proposal for #3825 enhancement (forgot one cleanup)

comment:1 Changed 8 years ago by brandon

Owner: set to brandon

comment:2 Changed 8 years ago by brandon

Milestone: 1.31.3.3
Resolution: fixed
Status: newclosed

Added in r6332.

comment:3 Changed 6 years ago by jitter

Keywords: needsDocs added

comment:4 Changed 6 years ago by kswedberg

Keywords: needsDocs removed

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

Note: See TracTickets for help on using tickets.