Bug Tracker

Ticket #3825 (closed enhancement: fixed)

Opened 6 years ago

Last modified 3 years ago

enhance .toggleClass

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

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

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

Change History

Changed 6 years ago by iraebrasil

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

comment:1 Changed 6 years ago by brandon

  • Owner set to brandon

comment:2 Changed 5 years ago by brandon

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

Added in r6332.

comment:3 Changed 4 years ago by jitter

  • Keywords needsDocs added

comment:4 Changed 3 years ago by kswedberg

  • Keywords needsDocs removed

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

Note: See TracTickets for help on using tickets.