I have a little problem when I need to count the level of nesting elements. The problem is that a parent can contain multiple children, and children can have their own children.
Please see where I want to start the countdown (marked with the text βI start hereβ).
HTML:
<div class="main_set"> <div class="child_set"> <div class="child_set"> <div class="child_set">I start here!</div> </div> <div class="child_set"></div> </div> <div class="child_set"> <div class="child_set"></div> </div> </div>
I tried a couple of things to get a score of 3.
For example, my last attempt:
$(this).closest('.main_set').find('.child_set');
This one obviously returns 6 tho for counting all child_sets.
How to read child_set elements from the initial place to main_set , taking into account only nesting. So basically in my example, how to get score 3?
source share