.addClass() | div add class js
Description:Addsthespecifiedclass(es)toeachelementinthesetofmatchedelements.Itsimportanttonotethatthismethoddoesnotreplaceaclass.Itsimplyaddstheclass,appendingittoanywhichmayalreadybeassignedtotheelements.BeforejQueryversion1.12/2.2,the.addClass()methodmanipulatedtheclassNamepropertyoftheselectedelements,nottheclassattribute.Oncethepropertywaschanged,itwasthebrowserthatupdatedtheattributeaccordingly.AnimplicationofthisbehaviorwasthatthismethodonlyworkedfordocumentswithHTMLDOMsemantics(e.g.,n...
Description: Adds the specified class(es) to each element in the set of matched elements.
Its 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.
Before jQuery version 1.12/2.2, 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 1.12/2.2, 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:
...