jQuery addClass to a tag problem

Posted by lander on Stack Overflow See other posts from Stack Overflow or by lander
Published on 2010-01-14T14:18:08Z Indexed on 2010/04/18 17:33 UTC
Read the original article Hit count: 366

Filed under:
|
|
|

I have this in my html code:

<ul id="navlist"
<li id="tabItem1"><a href="#">Item one</a></li>
<li id="tabItem2"><a href="#">Item two</a></li>
<li id="tabItem3"><a href="#">Item three</a></li>
<li id="tabItem4"><a href="#">Item four</a></li>
</ul>

I want to add a class to the a element with jquery like this: (its not working)

var currentTab = 1;

$(document).ready(function()
{        
  $("li#tabItem" + currentTab + ":has(a)").addClass("navlistHover");
  //console.log("li#tabItem" + currentTab + ":has(a)");
});

When a delete the a element and do it like the next example, than there is no problem.

$("li#tabItem" + currentTab).addClass("navlistHover");

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about addclass