thomagron thomagron - 5 months ago 25
HTML Question

Show div on click and hide on next click

I want to show information based on the item that it is clicked on.
I have some jquery code that works, but not when there are multiple div's in a div.

Here, the first part is what I want, the second part doesn't work because there are div's in the main div. hope that makes sense. How do i make it work?

I think it has something to do with :

$("#parent2").find("div:eq('" + i + "')").show().siblings().hide();



You have to toggle direct descendants, if you just find('div') it will find nested too.

So you can do either this:

$("#parent2 > div:eq('" + i + "')").show().siblings().hide();

or this:

$("#parent2").children("div:eq('" + i + "')").show().siblings().hide();