Skip to content

Commit 51a4be9

Browse files
committed
Document that addClass and removeClass change the attribute
Fixes jquerygh-814
1 parent 4e65b6d commit 51a4be9

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

entries/addClass.xml

Lines changed: 2 additions & 0 deletions
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>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>
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

Lines changed: 2 additions & 0 deletions
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>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>
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)