AddClass (class) adds the specified class name for each matching element. Adds the specified class (es) to each of the set of matched elements. Return Value
JQuery
Parameters
Class(String): one or more CSS class names to be added to the element. Separate them with spaces.
Example
Add the 'selected' class to the matched element.
HTML code:
<P> Hello </p>
JQuery code:
$ ("P"). addClass ("selected ");
Result:
[<P class = "selected"> Hello </p>]
Add the selected highlight class to the matched element
HTML code:
<P> Hello </p>
JQuery code:
$ ("P"). addClass ("selected highlight ");
Result:
[<P class = "selected highlight"> Hello </p>] ------------------------------------------------------------------------------------------------------------------------------ removeClass (class) deletes all or specified classes from all matching elements. Removes all or the specified class (es) from the set of matched elements. Return Value
JQuery
Parameters
Class(String): (optional) one or more CSS class names to be deleted. Separate them with spaces.
Example
Delete the 'selected' class from the matched element.
HTML code:
<P class = "selected first"> Hello </p>
JQuery code:
$ ("P"). removeClass ("selected ");
Result:
[<P> Hello </p>]
Delete all classes of matching elements
HTML code:
<P class = "selected first"> Hello </p>
JQuery code:
$ ("P"). removeClass ();
Result:
[<P> Hello </p>] When toggleClass (class) exists (does not exist), delete (ADD) a class. Adds the specified class if it is not present, removes the specified class if it is present. Return Value
JQuery
Parameters
Class(String): CSS Class Name
Example
Switch the 'selected' class to the matching element.
HTML code:
<P> Hello </p> <p class = "selected"> Hello Again </p>
JQuery code:
$ ("P"). toggleClass ("selected ");
Result:
[<P class = "selected"> Hello </p>, <p> Hello Again </p>]