I am having some problems with the sub nav on this site I am building. I dont think I am selecting items properly in my jquery. Im sure its just a little thing that needs to be done, but I dont know how to do it.
I am trying to make it so when you click on one of the subnav links a different div will open up revealing a color. For some reason when I click on a link it only reveals the first(red) div.
If you can help that would be great!
The problem is with this line:
var $menuelement = $('.thumb').eq($(this).parent().index());
a.subnav
's direct parent is an h4
. Using index()
on this element would mean you want the index of that h4
in relation to its siblings (there are none). You actually want the closest li
ancestor.
Use:
var $menuelement = $('.thumb').eq($(this).closest("li").index());
Updated fiddle: http://jsfiddle.net/286LV/
I updated the fiddle: http://jsfiddle.net/ZDErp/1/
What I did was us the href
attribute as the selector for the div to show.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.