add multiple classes jquery – How to Add and Remove multiple classes in jQuery ?

add multiple classes jquery – You can separate multiple classes with the space: like as $(“p”).addClass(“class1 class2 class3”); Jquery addclass() is used to add one or multiple classes dynamically to the selected element.

add multiple classes jquery

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

Also Read This πŸ‘‰   remove duplicate characters in a string javascript

Add and remove multiple classes in jQuery

$("p").addClass("myClass yourClass");

How to Add and Remove multiple classes in jQuery ?

<script src = "">

			.color {<br />
				color: red;<br />
			}<br />
			.fontWeight {<br />
				font-weight: bold;<br />
			}<br />


<h2 style="color: red;">Pakainfo</h2>
click here

			$('#Pakainfo_UP').text("Click on button to add multiple"
				+ " classes to this element");
			function Pakainfo_Data() {
				$("#Pakainfo_UP").addClass("color fontWeight");
				$('#Pakainfo_DOWN').text("color and fontWeight,"
						+ " Both classes added");

Don’t Miss : Dynamically AddClass CSS Click Using JQuery

Add multiple classes in jQuery



separated by a space


$( "div" ).addClass( "firstCls SecondCls" );

$( "div" ).addClass( "firstCls SecondCls ThirdCls FourthCls" );


using function in addClass() method

$( "div" ).addClass(function( index, class ) {
  var addedClass;
  if ( class === "pink" ) {
    addedClass = "green";
    $( "p" ).text( "There is one green div" );
  return addedClass;

Don’t Miss : JQuery Multiple Class Selectors Match

Also Read This πŸ‘‰   Laravel 5.8 Form Validation Using Jquery

I hope you get an idea about add multiple classes jquery.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.