You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<desc>A boolean value to determine whether the class should be added or removed.</desc>
23
-
</argument>
24
-
</signature>
25
-
<signature>
26
-
<added>1.4</added>
27
-
<argumentname="function"type="Function">
28
-
<argumentname="index"type="Integer" />
29
-
<argumentname="className"type="String" />
30
-
<argumentname="state"type="Boolean" />
31
-
<returntype="String" />
32
-
<desc>A function that returns class names to be toggled in the class attribute of each element in the matched set. Receives the index position of the element in the set, the old class value, and the state as arguments.</desc>
<desc>A boolean value to determine whether the class should be added or removed.</desc>
36
-
</argument>
37
-
</signature>
38
-
<desc>Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the state argument.</desc>
39
-
<longdesc>
40
-
<p>Before jQuery version 1.12/2.2, the <code>.toggleClass()</code> method manipulated the <code>className</code> <em>property</em> of the selected elements, not the <code>class</code> <em>attribute</em>. Once the property was changed, it was the browser that updated the attribute accordingly. An implication of this behavior was that this method only worked for documents with HTML DOM semantics (e.g., not pure XML documents).</p>
41
-
<p>As of jQuery 1.12/2.2, this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the <code>class</code> <em>attribute</em> is used instead. So, <code>.toggleClass()</code> can be used on XML or SVG documents.</p>
42
-
<p>This method takes one or more class names as its parameter. In the first version, if an element in the matched set of elements already has the class, then it is removed; if an element does not have the class, then it is added. For example, we can apply <code>.toggleClass()</code> to a simple <code><div></code>: </p>
<desc>One or more class names (separated by spaces) to be toggled for each element in the matched set.</desc>
9
+
</argument>
10
+
</signature>
11
+
<signature>
12
+
<added>1.3</added>
13
+
<argumentname="className"type="String">
14
+
<desc>One or more class names (separated by spaces) to be toggled for each element in the matched set.</desc>
15
+
</argument>
16
+
<argumentname="state"type="Boolean">
17
+
<desc>A Boolean (not just truthy/falsy) value to determine whether the class should be added or removed.</desc>
18
+
</argument>
19
+
</signature>
20
+
<signature>
21
+
<added>1.4</added>
22
+
<argumentname="function"type="Function">
23
+
<argumentname="index"type="Integer" />
24
+
<argumentname="className"type="String" />
25
+
<argumentname="state"type="Boolean" />
26
+
<returntype="String" />
27
+
<desc>A function that returns class names to be toggled in the class attribute of each element in the matched set. Receives the index position of the element in the set, the old class value, and the state as arguments.</desc>
<desc>A boolean value to determine whether the class should be added or removed.</desc>
31
+
</argument>
32
+
</signature>
33
+
<desc>Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the state argument.</desc>
34
+
<longdesc>
35
+
<p>This method takes one or more class names as its parameter. In the first version, if an element in the matched set of elements already has the class, then it is removed; if an element does not have the class, then it is added. For example, we can apply <code>.toggleClass()</code> to a simple <code><div></code>: </p>
36
+
<pre><code>
44
37
<div class="tumble">Some text.</div>
45
-
</code></pre>
46
-
<p>The first time we apply <code>$( "div.tumble" ).toggleClass( "bounce" )</code>, we get the following:</p>
47
-
<pre><code>
38
+
</code></pre>
39
+
<p>The first time we apply <code>$( "div.tumble" ).toggleClass( "bounce" )</code>, we get the following:</p>
<p>The second time we apply <code>$( "div.tumble" ).toggleClass( "bounce" )</code>, the <code><div></code> class is returned to the single <code>tumble</code> value:</p>
<p>Applying <code>.toggleClass( "bounce spin" )</code> to the same <code><div></code> alternates between <code><div class="tumble bounce spin"></code> and <code><div class="tumble"></code>.</p>
53
-
<p>The second version of <code>.toggleClass()</code> uses the second parameter for determining whether the class should be added or removed. If this parameter's value is <code>true</code>, then the class is added; if <code>false</code>, the class is removed. In essence, the statement:</p>
54
-
<pre><code>
42
+
</code></pre>
43
+
<p>The second time we apply <code>$( "div.tumble" ).toggleClass( "bounce" )</code>, the <code><div></code> class is returned to the single <code>tumble</code> value:</p>
<p>Applying <code>.toggleClass( "bounce spin" )</code> to the same <code><div></code> alternates between <code><div class="tumble bounce spin"></code> and <code><div class="tumble"></code>.</p>
46
+
<p>The second version of <code>.toggleClass()</code> uses the second parameter for determining whether the class should be added or removed. If this parameter's value is <code>true</code>, then the class is added; if <code>false</code>, the class is removed. In essence, the statement:</p>
<p><strong>As of jQuery 1.4</strong>, if no arguments are passed to <code>.toggleClass()</code>, all class names on the element the first time <code>.toggleClass()</code> is called will be toggled. Also as of jQuery 1.4, the class name to be toggled can be determined by passing in a function.</p>
66
-
<pre><code>
57
+
</code></pre>
58
+
<p><strong>As of jQuery 1.4</strong>, if no arguments are passed to <code>.toggleClass()</code>, all class names on the element the first time <code>.toggleClass()</code> is called will be toggled. Also as of jQuery 1.4, the class name to be toggled can be determined by passing in a function.</p>
59
+
<pre><code>
67
60
$( "div.foo" ).toggleClass(function() {
68
61
if ( $( this ).parent().is( ".bar" ) ) {
69
62
return "happy";
70
63
} else {
71
64
return "sad";
72
65
}
73
66
});
74
-
</code></pre>
75
-
<p>This example will toggle the <code>happy</code> class for <code><div class="foo"></code> elements if their parent element has a class of <code>bar</code>; otherwise, it will toggle the <code>sad</code> class.</p>
76
-
</longdesc>
77
-
<example>
78
-
<desc>Toggle the class 'highlight' when a paragraph is clicked.</desc>
79
-
<code><![CDATA[
67
+
</code></pre>
68
+
<p>This example will toggle the <code>happy</code> class for <code><div class="foo"></code> elements if their parent element has a class of <code>bar</code>; otherwise, it will toggle the <code>sad</code> class.</p>
69
+
</longdesc>
70
+
<example>
71
+
<desc>Toggle the class 'highlight' when a paragraph is clicked.</desc>
72
+
<code><![CDATA[
80
73
$( "p" ).click(function() {
81
74
$( this ).toggleClass( "highlight" );
82
75
});
83
76
]]></code>
84
-
<css><![CDATA[
77
+
<css><![CDATA[
85
78
p {
86
79
margin: 4px;
87
80
font-size: 16px;
@@ -95,16 +88,16 @@ $( "p" ).click(function() {
95
88
background: yellow;
96
89
}
97
90
]]></css>
98
-
<html><![CDATA[
91
+
<html><![CDATA[
99
92
<p class="blue">Click to toggle</p>
100
93
<p class="blue highlight">highlight</p>
101
94
<p class="blue">on these</p>
102
95
<p class="blue">paragraphs</p>
103
96
]]></html>
104
-
</example>
105
-
<example>
106
-
<desc>Add the "highlight" class to the clicked paragraph on every third click of that paragraph, remove it every first and second click.</desc>
107
-
<code><![CDATA[
97
+
</example>
98
+
<example>
99
+
<desc>Add the "highlight" class to the clicked paragraph on every third click of that paragraph, remove it every first and second click.</desc>
100
+
<code><![CDATA[
108
101
var count = 0;
109
102
$( "p" ).each(function() {
110
103
var $thisParagraph = $( this );
@@ -116,7 +109,7 @@ $( "p" ).each(function() {
116
109
});
117
110
});
118
111
]]></code>
119
-
<css><![CDATA[
112
+
<css><![CDATA[
120
113
p {
121
114
margin: 4px;
122
115
font-size: 16px;
@@ -130,17 +123,16 @@ $( "p" ).each(function() {
130
123
background: red;
131
124
}
132
125
]]></css>
133
-
<html><![CDATA[
126
+
<html><![CDATA[
134
127
<p class="blue">Click to toggle (<span>clicks: 0</span>)</p>
0 commit comments