Skip to content

Commit 4651f44

Browse files
committed
Document that addClass and removeClass change the attribute
Fixes gh-814 Closes gh-846
1 parent 4e65b6d commit 4651f44

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

entries/addClass.xml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +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>Before jQuery version 3.0, 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 3.0 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>
2224
<p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>
2325
<pre><code>
2426
$( "p" ).addClass( "myClass yourClass" );

entries/removeClass.xml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +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>Before jQuery version 3.0, 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 3.0 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>
2224
<p>More than one class may be removed at a time, separated by a space, from the set of matched elements, like so:</p>
2325
<pre><code>
2426
$( "p" ).removeClass( "myClass yourClass" )

0 commit comments

Comments
 (0)