jQuery Tutorial
jQuery addClass() Method With Examples
What is addClass method in jQuery?
The addClass()
method in jQuery assigns one or more class names to the elements that have been selected.
This method only adds one or more class names to the class attribute, not removing existing class attributes.
To add more than one class, use spaces to separate the names.
Syntax of jQuery addClass method
$(selector).addClass(classname,function(index,currentclass))
Example of addClass method in jQuery
To the first
element, add a class name:
$("button").click(function(){
$("p:first").addClass("intro");
});