I’m creating a menu that is nested within
<a href="#">
<div class="container"> </div>
<div class="title"> </div>
<div class="Chapter"> </div>
</a>
my PHP foreachloop : tells me how many of these container elements I have could be 10 or 20.
what i’m trying to do is use Jquery to tell me what the child number of the menu item I clicked on. currently i’m using
var count2 = $(this).parent().index();
Then i’m saving the parameter into a cookie, with createCookie("menu",count2);
the cookie is setting correctly and now contains a string say “10”.
my question is: which jquery function can I use to receive the parameter of the child
number of the menu items and add a class to that menu item.
something along the lines of
if (readCookie("menu") != null) {
$("a .container:nth-child(readCookie("menu")").removeClass("").addClass("active");
}
Try this.
eq(x)returns the x-th result of your jquery selector.