How to target class name by class inside another class
I have divs like this.
<div class"parent">
<div class"child">
Some Stuff Here
</div>
</div>
<div class"parent">
<div class"child">
Some other kinda Stuff Here
</div>
</div>
I want to click on the parent class and show the child class only inside this parent, without showing other classes of children in other parent classes.
$(document).on('click', '.parent', function(){
$(this).find($('.child').show(500));
});
+4
4 answers
Do not use the selector $('.child')in the search, as it will return the entire child in the DOM and find $(this).find($('.child').show(500));should be$(this).find('.child').show(500);
Also fix html class"parent"should be class="parent", the same applies toclass"child"
$(document).on('click', '.parent', function(){
$(this).find('.child').show(500);
});
+1