How to use addClass() Method in JQuery

In this article, I will explain use of addClass() Method in JQuery.
  • 2276

JQuery CSS addclass() Method

  • addClass() method adds one or more classes to the selected elements.

  • addClass() method does not remove existing class attributes.

  • addClass() method adds only one or more values to the class attribute.

  • We can add more than one class at a time, separated by space.




The following example shows how to addclass() method in jquery.

<!DOCTYPE html>



<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("button").click(function () {





<style type="text/css">









<h1>This is addclass() method example</h1>

<p>One paragraph.</p>

<p>Second paragraph.</p>

<button>Click for Add a class to the first p element</button>





addclass method.jpg

Further Readings

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.