From 51a4be98cb60555b875a0b7a63597df1ee74d1f2 Mon Sep 17 00:00:00 2001 From: Aurelio De Rosa Date: Mon, 14 Dec 2015 02:04:06 +0000 Subject: [PATCH 1/2] Document that addClass and removeClass change the attribute Fixes gh-814 --- entries/addClass.xml | 2 ++ entries/removeClass.xml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/entries/addClass.xml b/entries/addClass.xml index 476251d8..fc261468 100644 --- a/entries/addClass.xml +++ b/entries/addClass.xml @@ -19,6 +19,8 @@ Adds the specified class(es) to each element in the set of matched elements.

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.

+

The .addClass() method manipulates the className property of the selected elements, not the class attribute. 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).

+

As of jQuery 3.0 this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the class attribute is used instead. So, .addClass() can be used on XML or SVG documents.

More than one class may be added at a time, separated by a space, to the set of matched elements, like so:


 $( "p" ).addClass( "myClass yourClass" );
diff --git a/entries/removeClass.xml b/entries/removeClass.xml
index 8bb11196..7f715842 100644
--- a/entries/removeClass.xml
+++ b/entries/removeClass.xml
@@ -19,6 +19,8 @@
   Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
   
     

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.

+

The .removeClass() method manipulates the className property of the selected elements, not the class attribute. Once the property is changed, it's the browser that updates the attribute accordingly. This means that when the class 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).

+

As of jQuery 3.0 this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the class attribute is used instead. So, .removeClass() can be used on XML or SVG documents.

More than one class may be removed at a time, separated by a space, from the set of matched elements, like so:


 $( "p" ).removeClass( "myClass yourClass" )

From defed3aceae1e4619ec0a97dfa3c6a2bcc6fc2a7 Mon Sep 17 00:00:00 2001
From: Aurelio De Rosa 
Date: Mon, 14 Dec 2015 20:44:42 +0000
Subject: [PATCH 2/2] Updated based on feedback

---
 entries/addClass.xml    | 2 +-
 entries/removeClass.xml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/entries/addClass.xml b/entries/addClass.xml
index fc261468..8b8a0564 100644
--- a/entries/addClass.xml
+++ b/entries/addClass.xml
@@ -19,7 +19,7 @@
   Adds the specified class(es) to each element in the set of matched elements.
   
     

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.

-

The .addClass() method manipulates the className property of the selected elements, not the class attribute. 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).

+

Before jQuery version 3.0, the .addClass() method manipulated the className property of the selected elements, not the class attribute. 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).

As of jQuery 3.0 this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the class attribute is used instead. So, .addClass() can be used on XML or SVG documents.

More than one class may be added at a time, separated by a space, to the set of matched elements, like so:


diff --git a/entries/removeClass.xml b/entries/removeClass.xml
index 7f715842..6a85ea72 100644
--- a/entries/removeClass.xml
+++ b/entries/removeClass.xml
@@ -19,7 +19,7 @@
   Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
   
     

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.

-

The .removeClass() method manipulates the className property of the selected elements, not the class attribute. Once the property is changed, it's the browser that updates the attribute accordingly. This means that when the class 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).

+

Before jQuery version 3.0, the .removeClass() method manipulated the className property of the selected elements, not the class attribute. Once the property was changed, it was the browser that updated the attribute accordingly. This means that when the class 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).

As of jQuery 3.0 this behavior is changed to improve the support for XML documents, including SVG. Starting from this version, the class attribute is used instead. So, .removeClass() can be used on XML or SVG documents.

More than one class may be removed at a time, separated by a space, from the set of matched elements, like so: