Adding jQuery CSS Class

Every month my work sends our team to the Coldfusion Users Group in Sacramento California. This month the presentation was on jQuery which included specific examples and showed how useful jQuery can be in almost any situation. I decided to take it upon myself to learn some jQuery, and I will be posting about my experiences over the next few months.

My first self taught lesson is how to add a css class to an html element. It's really simple to do this, but I feel like I need to create a journal of my learning experiences in case I need to come back and reference some code.

If you haven't used jquery before, this code calls the $(document).ready() function that can be used to inject css classes into html elements. For instance, if I wanted to add a small caps class to every <h1> tag on the page, I would write this bit of code:

$(document).ready(function() {
$('h1').addClass('smallcaps');
});

And that's it. Although this doesn't entirely make sense yet because I can directly define this bit of code in CSS; I know it will change later as I start to learn more.

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment