Side navigation
#3825 closed enhancement (fixed)
Opened January 11, 2009 04:57PM UTC
Closed May 02, 2009 09:15PM UTC
Last modified September 19, 2011 12:47AM UTC
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)
Change History (4)
Changed May 02, 2009 07:31PM UTC by comment:1
| owner: | → brandon |
|---|
Changed May 02, 2009 09:15PM UTC by comment:2
| milestone: | 1.3 → 1.3.3 |
|---|---|
| resolution: | → fixed |
| status: | new → closed |
Added in r6332.
Changed January 09, 2011 11:18PM UTC by comment:3
| keywords: | → needsDocs |
|---|
Changed September 19, 2011 12:47AM UTC by comment:4
| keywords: | needsDocs |
|---|
added documentation at http://api.jquery.com/toggleClass/