Skip to main content

Add CSS Class to an Element Using jQuery

Submitted by admin on Thu, 12/16/2021 - 18:37
jquery-add-css-class

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


$('element').addClass('class-name');

To add more than one class, use below syntax.


$('element').addClass('class-one class-two');

Example

In below example, we will add a class named newclass to header region.


<script>
$(document).ready(function(){
  $('header').addClass('newclass');
})
</script>

Tutorial Category