jQuery addClass

In this post we are learn about jquery addClass function. usign this function you can add CSS class in HTML any tag. addClass function you can use with jquery all events like click,change,hover etc..

when you use this function at that time first you add jquery file or cdn. nicesnippets.com provide free source code of jquery addClass function example with demo code. you can simply copy past in your project. this is simple and best way of addClass function.

Example Demo


nicesnippets.com For Learning jQuery


Js Code

$('.add_red_color').click(function() {
    $('#live_change').addClass("redcolor");
});

$('.add_red_color').click(function() {
    $('#remove_red_color').removeClass("redcolor");
});

Html Code

<hr>
	<h1 class="live_change" align="center">nicesnippets.com For Learning jQuery</h1>
<hr>

<button class="add_red_color">Add Red Color</button>
<button class="remove_red_color">Remove Red Color</button>

Css Code

.redcolor{
	color:red;
}
Add