Skip to content

Document that addClass and removeClass change the attribute #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions entries/addClass.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<desc>Adds the specified class(es) to each element in the set of matched elements.</desc>
<longdesc>
<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>
<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>
<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>
<p>More than one class may be added at a time, separated by a space, to the set of matched elements, like so:</p>
<pre><code>
$( "p" ).addClass( "myClass yourClass" );
Expand Down
2 changes: 2 additions & 0 deletions entries/removeClass.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<desc>Remove a single class, multiple classes, or all classes from each element in the set of matched elements.</desc>
<longdesc>
<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>
<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>
<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>
<p>More than one class may be removed at a time, separated by a space, from the set of matched elements, like so:</p>
<pre><code>
$( "p" ).removeClass( "myClass yourClass" )
Expand Down