Using .className property: This property is used to add a class name to the selected element.
It is used to set the className property.
element.className += "newClass";
It is used to return the className property.
- newClass: It specifies the element’s class name. For applying multiple classes, it needs to separate by space.
Return value: It is of string type which represents the class or list of classes of elements with space-separated.
Example: This example uses the .className property to add a class name.
Using .add() method: This method is used to add a class name to the selected element.
Example: This example uses .add() method to add class name.
- Google Chrome 22.0
- Microsoft Edge 12.0
- Internet Explorer 5.0
- Firefox 1.0
- Opera 8.0
- Safari 1.0