July 8, 2010
Find class inside class with jQuery selectors
Question by fearofawhackplanet
I’m trying to do something like the following in jQuery
$('.container').siblings('.outerClass > .innerClass')
where I’m looking for:
<div class="container"></div>
<div class="outerClass">
<div class="innerClass">
find me!
</div>
</div>
I can’t get the syntax right.
Answer by Felix Kling
And another one (but this should work) (assuming you want to get the element with class innerClass
):
$('.container').siblings('.outerClass').children('.innerClass')
Answer by Starx
You can also do this to directly select the required elements
$(".outerClass").children(".innerClass").click(function() {
//Do your stuff
});