Skip to content

Commit d6d3e7a

Browse files
AurelioDeRosatimmywil
authored andcommitted
toggleClass: Document deprecation of a signature
Fixes gh-851 Closes gh-860
1 parent 5854b44 commit d6d3e7a

File tree

1 file changed

+90
-86
lines changed

1 file changed

+90
-86
lines changed

entries/toggleClass.xml

+90-86
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,80 @@
11
<?xml version="1.0"?>
2-
<entry type="method" name="toggleClass" return="jQuery">
3-
<title>.toggleClass()</title>
4-
<signature>
5-
<added>1.0</added>
6-
<argument name="className" type="String">
7-
<desc>One or more class names (separated by spaces) to be toggled for each element in the matched set.</desc>
8-
</argument>
9-
</signature>
10-
<signature>
11-
<added>1.3</added>
12-
<argument name="className" type="String">
13-
<desc>One or more class names (separated by spaces) to be toggled for each element in the matched set.</desc>
14-
</argument>
15-
<argument name="state" type="Boolean">
16-
<desc>A Boolean (not just truthy/falsy) value to determine whether the class should be added or removed.</desc>
17-
</argument>
18-
</signature>
19-
<signature>
20-
<added>1.4</added>
21-
<argument name="state" optional="true" type="Boolean">
22-
<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-
<argument name="function" type="Function">
28-
<argument name="index" type="Integer" />
29-
<argument name="className" type="String" />
30-
<argument name="state" type="Boolean" />
31-
<return type="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>
33-
</argument>
34-
<argument name="state" optional="true" type="Boolean">
35-
<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>&lt;div&gt;</code>: </p>
43-
<pre><code>
2+
<entries>
3+
<entry type="method" name="toggleClass" return="jQuery">
4+
<title>.toggleClass()</title>
5+
<signature>
6+
<added>1.0</added>
7+
<argument name="className" type="String">
8+
<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+
<argument name="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+
<argument name="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+
<argument name="function" type="Function">
23+
<argument name="index" type="Integer" />
24+
<argument name="className" type="String" />
25+
<argument name="state" type="Boolean" />
26+
<return type="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>
28+
</argument>
29+
<argument name="state" optional="true" type="Boolean">
30+
<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>&lt;div&gt;</code>: </p>
36+
<pre><code>
4437
&lt;div class="tumble"&gt;Some text.&lt;/div&gt;
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>
40+
<pre><code>
4841
&lt;div class="tumble bounce"&gt;Some text.&lt;/div&gt;
49-
</code></pre>
50-
<p>The second time we apply <code>$( "div.tumble" ).toggleClass( "bounce" )</code>, the <code>&lt;div&gt;</code> class is returned to the single <code>tumble</code> value:</p>
51-
<pre><code>&lt;div class="tumble"&gt;Some text.&lt;/div&gt;</code></pre>
52-
<p>Applying <code>.toggleClass( "bounce spin" )</code> to the same <code>&lt;div&gt;</code> alternates between <code>&lt;div class="tumble bounce spin"&gt;</code> and <code>&lt;div class="tumble"&gt;</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>&lt;div&gt;</code> class is returned to the single <code>tumble</code> value:</p>
44+
<pre><code>&lt;div class="tumble"&gt;Some text.&lt;/div&gt;</code></pre>
45+
<p>Applying <code>.toggleClass( "bounce spin" )</code> to the same <code>&lt;div&gt;</code> alternates between <code>&lt;div class="tumble bounce spin"&gt;</code> and <code>&lt;div class="tumble"&gt;</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>
47+
<pre><code>
5548
$( "#foo" ).toggleClass( className, addOrRemove );
56-
</code></pre>
57-
<p>is equivalent to:</p>
58-
<pre><code>
49+
</code></pre>
50+
<p>is equivalent to:</p>
51+
<pre><code>
5952
if ( addOrRemove ) {
6053
$( "#foo" ).addClass( className );
6154
} else {
6255
$( "#foo" ).removeClass( className );
6356
}
64-
</code></pre>
65-
<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>
6760
$( "div.foo" ).toggleClass(function() {
6861
if ( $( this ).parent().is( ".bar" ) ) {
6962
return "happy";
7063
} else {
7164
return "sad";
7265
}
7366
});
74-
</code></pre>
75-
<p>This example will toggle the <code>happy</code> class for <code>&lt;div class="foo"&gt;</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>&lt;div class="foo"&gt;</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[
8073
$( "p" ).click(function() {
8174
$( this ).toggleClass( "highlight" );
8275
});
8376
]]></code>
84-
<css><![CDATA[
77+
<css><![CDATA[
8578
p {
8679
margin: 4px;
8780
font-size: 16px;
@@ -95,16 +88,16 @@ $( "p" ).click(function() {
9588
background: yellow;
9689
}
9790
]]></css>
98-
<html><![CDATA[
91+
<html><![CDATA[
9992
<p class="blue">Click to toggle</p>
10093
<p class="blue highlight">highlight</p>
10194
<p class="blue">on these</p>
10295
<p class="blue">paragraphs</p>
10396
]]></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[
108101
var count = 0;
109102
$( "p" ).each(function() {
110103
var $thisParagraph = $( this );
@@ -116,7 +109,7 @@ $( "p" ).each(function() {
116109
});
117110
});
118111
]]></code>
119-
<css><![CDATA[
112+
<css><![CDATA[
120113
p {
121114
margin: 4px;
122115
font-size: 16px;
@@ -130,17 +123,16 @@ $( "p" ).each(function() {
130123
background: red;
131124
}
132125
]]></css>
133-
<html><![CDATA[
126+
<html><![CDATA[
134127
<p class="blue">Click to toggle (<span>clicks: 0</span>)</p>
135128
<p class="blue highlight">highlight (<span>clicks: 0</span>)</p>
136129
<p class="blue">on these (<span>clicks: 0</span>)</p>
137130
<p class="blue">paragraphs (<span>clicks: 0</span>)</p>
138131
]]></html>
139-
</example>
140-
<example>
141-
<desc>Toggle the class name(s) indicated on the buttons for each div.
142-
</desc>
143-
<css><![CDATA[
132+
</example>
133+
<example>
134+
<desc>Toggle the class name(s) indicated on the buttons for each div.</desc>
135+
<css><![CDATA[
144136
.wrap > div {
145137
float: left;
146138
width: 100px;
@@ -158,7 +150,7 @@ $( "p" ).each(function() {
158150
background-color: cornsilk;
159151
}
160152
]]></css>
161-
<html><![CDATA[
153+
<html><![CDATA[
162154
<div class="buttons">
163155
<button>toggle</button>
164156
<button class="a">toggle a</button>
@@ -173,7 +165,7 @@ $( "p" ).each(function() {
173165
<div class="a c"></div>
174166
</div>
175167
]]></html>
176-
<code><![CDATA[
168+
<code><![CDATA[
177169
var cls = [ "", "a", "a b", "a b c" ];
178170
var divs = $( "div.wrap" ).children();
179171
var appendClass = function() {
@@ -198,11 +190,23 @@ $( "a" ).on( "click", function( event ) {
198190
appendClass();
199191
});
200192
]]></code>
201-
</example>
202-
<category slug="attributes"/>
203-
<category slug="manipulation/class-attribute"/>
204-
<category slug="css"/>
205-
<category slug="version/1.0"/>
206-
<category slug="version/1.3"/>
207-
<category slug="version/1.4"/>
208-
</entry>
193+
</example>
194+
<category slug="attributes"/>
195+
<category slug="manipulation/class-attribute"/>
196+
<category slug="css"/>
197+
<category slug="version/1.0"/>
198+
<category slug="version/1.3"/>
199+
<category slug="version/1.4"/>
200+
</entry>
201+
<entry type="method" name="toggleClass" return="jQuery" deprecated="3.0">
202+
<signature>
203+
<added>1.4</added>
204+
<argument name="state" optional="true" type="Boolean">
205+
<desc>A boolean value to determine whether the class should be added or removed.</desc>
206+
</argument>
207+
</signature>
208+
<longdesc>
209+
<div class="warning"><strong>This signature (only!) is deprecated as of jQuery 3.0</strong>.</div>
210+
</longdesc>
211+
</entry>
212+
</entries>

0 commit comments

Comments
 (0)