jQuery.addClass - Add a CSS class dynamically

by Dave Reeder 24. September 2009 21:28

The .addClass method will add a CSS class to the selected element on a page. For example, imagine we have a navigaton bar which contains our page links and the homepage link has an ID of "navHome". We can use jQuery to select the link in our nav and add the class very easily:

<script type="text/javascript"> 
        $(document).ready(function() {
            $('#navHome').addClass('current');
        });
</script> 

Obviously this is just a simple example of the .addClass method, it can be used for anything you require.

Tags: , ,

Comments

10/28/2009 4:08:33 PM #

thanks! this code is basic but nicely done presentation. short and concise.

on line dating

1/28/2010 9:52:39 PM #

The important thing is not to stop questioning.

Loans in South Carolina

Comments are closed