apply styles by using classname in jQuery

by Developer 19. January 2010 18:56

In my previous posts, you learn how to apply CSS styles by using element id and element type. In this article I am explaining how to apply styles by using classname of an element.

 

<html>
    <head>
        <title>This is jquery example for applying styles using classname</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('.pclass').addClass('italicbold');
            });   
        </script>
        <style type="text/css">
        .italicbold
        {
            font-style:italic;font-weight:bold;
        }
        </style>
    </head>
    <body>
        <p class="pclass">
            This is jquery example to make text as italic and bold by using class name
        </p>
    </body>
</html>

In the above code we have one <p> tag with class name as "pclass".

$('.pclass').addClass('italicbold') will apply the CSS class "italicbold" to the element whose classname is "pclass".

 

Download source code: styles using classname.zip (35.71 kb)

Comments

4/28/2010 5:16:07 PM #

Manchester Solicitors

Hi well done top blog in from manchester.

Manchester Solicitors

4/29/2010 6:38:39 AM #

wide sally

Hey really good blog!!!

wide sally

4/29/2010 7:21:49 PM #

UnitedQ

I do not generally reply to posts but I'll in this instance....)

UnitedQ

4/30/2010 1:38:14 AM #

Darnell JenkinsMiami

You created some good factors there.
I do a research about the topic and found many people will agree together with your blog.

Darnell JenkinsMiami

5/4/2010 5:32:25 AM #

Renay Sobol

Just thought I'd leave a comment and see if it gets posted. Lately I have been jumping from one blog to another and will not know when to stop. I ended up here so I think I will finally take a break.

Renay Sobol

5/6/2010 9:10:57 AM #

Credit Card Machine Manuals

Hey.  Is there a reason why this page looks screwed up in Opera?  Anyway a bit of advice, do a second writeup soon!

Credit Card Machine Manuals

5/23/2010 2:57:02 PM #

table lamps for living room

You will never win if you never begin.

table lamps for living room

5/24/2010 1:23:38 AM #

table lamps for living room

If you take responsibility for yourself you will develop a hunger to accomplish your dreams.

table lamps for living room

6/29/2010 5:20:46 AM #

Proven Penis Enlargement

That was one with the most useful posts I have witnessed in a prolonged extended time. A amazing deal of appreciated, I�m likely to need to hang around here considerably much more.

Proven Penis Enlargement

6/30/2010 3:14:59 AM #

Adam Krynicki

Remarkable article, loads of fine material.  I am about to show my girlftriend and ask them what they think.

Adam Krynicki

6/30/2010 9:36:24 AM #

Best Penis Enlargement Product

Which is just epic. Thanks for the valuable post.

Best Penis Enlargement Product

7/7/2010 7:17:11 PM #

Jaymie Lawing

thanx apply styles by using class name in jquery

Jaymie Lawing

7/7/2010 7:18:04 PM #

Shaniqua Gawlak

I do not agree with everything in this post, but you do make some excellent things. I am very interested in this subject and I personally act alot of study as well. Either way it was a well thoughtout plus fine read so I figured I would leave u a note. Feel free to check out my internet site sometime and let me know what u think.

Shaniqua Gawlak

7/8/2010 6:15:09 AM #

Verifone Manuals

I know you are using Microsofts BlogEngine.NET but can you please tell me which theme that you are using?  I've been looking around and wanted one like the one here. I came from wordpress and am trying to figure out BlogEngine.

Verifone Manuals

7/9/2010 2:40:47 PM #

Kristian Nebred

I have been browsingonline a lot more than three hrs today, until now I by no means found any attractive article like yours. It's pretty worth enough for me. For my part, if all website owners and bloggers made fine content as you did, the web might be much more functional than ever before.

Kristian Nebred

7/9/2010 6:53:20 PM #

Hypercom T7Plus Manual

Hey Webmaster, I like blogengine.net but why did you chose it?  I mean it's so neat with the random avatars and draws people in, but what speficially made you want to install it?

Hypercom T7Plus Manual

7/12/2010 2:36:33 PM #

Alex Magouliotis

Whats happening, I found this site by mistake when I was going through Aol then I arrived to your web site. I must say your site is interesting I really like your theme! Right now I don�t have the free time at the present moment to fully browse your sitebut I have bookmarked it. I will be back in a day or 2 . Thanks for a good site.

Alex Magouliotis

7/12/2010 10:42:49 PM #

Ismael Mitman

Maby considere to write a apply styles by using class name in jquery company to put here adv

Ismael Mitman

7/26/2010 5:23:30 AM #

ediets review

I am surprised at the things I overlooked before I read this post. Thanks for the great information.

ediets review

7/27/2010 3:25:24 AM #

hypercom t7plus Manual

Well that makes 2 things that I learned this week.  This and google now has a ton of greasemonkey scripts which I just found out.  You learn something every day?  I got more than what I bargained for! hahaha.

hypercom t7plus Manual

7/27/2010 6:59:43 PM #

Modesto Veney

Just wanted to give you a shout from the valley of the sunlight, great information. Much appreciated.

Modesto Veney

7/28/2010 5:45:44 AM #

magnetic name badges

Just wanted to say hello from New York

magnetic name badges

7/28/2010 7:26:26 AM #

e-cig

It's a beautiful country, more people need to recognise that.

e-cig

7/28/2010 7:43:34 PM #

Charla Sartin

Tremendous-Duper website! I am loving it!! Will come back once more - taking you feeds also, Thanks.

Charla Sartin

Add comment




  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading



Page List

    Tag cloud