Here is my question. I am having this simple menu.
<div id="menu">
<ul>
<li> <a id="home" href="home.html"> home </a> </li>
<li> <a id="profile" href="profile.html"> profile</a> </li>
<ul>
</div>
and I wanna to use jQuery to add a class “.active” to the a tag with the id=”home”.
What I am writing is: $('a#home').addClass("active"); but is not working.
How can I access this nested tag and add some class??
Any suggestions would be highly appreciated!
Thanx
The typical mistake is to put your jQuery code in the header, but not wrapped in a ready event.
Make sure you have:
see here for a live test: http://jsfiddle.net/QdVLs/ (remember jsfiddle automartically wraps any code in a ready method like above)