.addClass( className ) :- Adds the specified class(es) to each of the set of matched elements

.addClass() method is used to add class to some elements.

Example :-

<style>

.myclass { color:red; font-size:25px; }

.paragraph { color:blue; font-size:20px; }

</style>

<script type=”text/javascript” src=”http://code.jquery.com/jquery-1.5.js”></script&gt;

<script type=”text/javascript”>

$(document).ready(function (){

$(‘div’).addClass(‘myclass’);

$(‘p’).addClass(‘paragraph’);

});

</script>

<div align=”center”>I am div1</div>

<p align=”center”>I am paragraph</div>

<div align=”center”>I am div2</div>

Output :-

Advertisements

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.