Skip to content

Commit 4a2f383

Browse files
AurelioDeRosatimmywil
authored andcommitted
Document that addClass and removeClass change the attribute
Fixes jquerygh-814 Closes jquerygh-846
1 parent cd7119b commit 4a2f383

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

entries/addClass.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<desc>Adds the specified class(es) to each element in the set of matched elements.</desc>
2020
<longdesc>
2121
<p>It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.</p>
22-
<p>The <code>.addClass()</code> method manipulates the <code>className</code> <em>property</em> of the selected elements, not the <code>class</code> <em>attribute</em>. Once the property is changed, it's the browser that updates the attribute accordingly. An implication of this behavior is that this method only works for documents with HTML DOM semantics (e.g., not pure XML documents).</p>
22+
<p>Before jQuery version 1.12/2.2, the <code>.addClass()</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>
23+
<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>.addClass()</code> can be used on XML or SVG documents.</p>
2324
<p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>
2425
<pre><code>
2526
$( "p" ).addClass( "myClass yourClass" );

entries/removeClass.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<desc>Remove a single class, multiple classes, or all classes from each element in the set of matched elements.</desc>
2020
<longdesc>
2121
<p>If a class name is included as a parameter, then only that class will be removed from the set of matched elements. If no class names are specified in the parameter, all classes will be removed.</p>
22-
<p>The <code>.removeClass()</code> method manipulates the <code>className</code> <em>property</em> of the selected elements, not the <code>class</code> <em>attribute</em>. Once the property is changed, it's the browser that updates the attribute accordingly. This means that when the <code>class</code> attribute is updated and the last class name is removed, the browser may set the attribute's value to an empty string instead of removing the attribute completely. An implication of this behavior is that this method only works for documents with HTML DOM semantics (e.g., not pure XML documents).</p>
22+
<p>Before jQuery version 1.12/2.2, the <code>.removeClass()</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. This means that when the <code>class</code> attribute was updated and the last class name was removed, the browser might have set the attribute's value to an empty string instead of removing the attribute completely. An implication of this behavior was that this method only worked for documents with HTML DOM semantics (e.g., not pure XML documents).</p>
23+
<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>.removeClass()</code> can be used on XML or SVG documents.</p>
2324
<p>More than one class may be removed at a time, separated by a space, from the set of matched elements, like so:</p>
2425
<pre><code>
2526
$( "p" ).removeClass( "myClass yourClass" )

0 commit comments

Comments
 (0)