Reputation: 345
I am having a hard time trying to figure out how to properly select a class inside the menu.
It worked fine until I put the menu in a ul. Can anyone tell me what is going on and how to fix it?
http://jsfiddle.net/nategines/7XrUk/
Upvotes: 0
Views: 74
Reputation: 6339
Sure. The problem is that you're calling index
on the link, which is a child of the li
, and so will always only be the first child. You want the index of its parent instead.
Fixed here: http://jsfiddle.net/7XrUk/1/
Upvotes: 0
Reputation: 8154
That's pretty vague, but this is the concept if the child is nested:
$('.menu').find('.class')
Upvotes: 0
Reputation: 149794
Here’s a working version: http://jsfiddle.net/3hbk7/
var $menuelement = $('.demo ul').eq($(this).index());//find the matching nth element in the menu
…should’ve been:
var $menuelement = $('.demo ul').eq($(this).parent().index());//find the matching nth element in the menu
Upvotes: 1