In this jQuery tutorial we will learn how to add new css class to any element (div / span / paragraph etc.) using jQuery.
Using jQuery addClass() method, we can add new CSS class to any element.
Syntax
1 | $('element').addClass('class-name'); |
To add more than one class, use below syntax.
1 | $('element').addClass('class-one class-two'); |
Example
In below example, we will add a class named newclass to header region.
1 2 3 4 5 | <script> $(document).ready(function(){ $('header').addClass('newclass'); }) </script> |