I have an unordered list with sub menus.
I have an unordered list and i want to print the number of child list items each list item contains , however, the function I wrote only returns 0.
If I replace $(this) with a class or ID then it works fine, however, it then prints the same number for every list item, and I need it to be dynamic, returning the .length or .size() of each individual list item.
Can you please guide me in the right direction? :)
/*atomic mass counter*/
$(document).ready(function(mass){
var atomic = $(this).parent('li').length;
$('.atom').html(atomic);
});
the class .atom is a child of each list item so the list looks something like this:
<ul>
<li>
<div class='atom'></div>
<ul>
<li><div class='atom'></div></li>
<li><div class='atom'></div></li>
</ul>
</li>
<li><div class='atom'></div></li>
<li><div class='atom'></div></li>
<li><div class='atom'></div></li>
</ul>
Here's a JSfiddle: https://jsfiddle.net/6gzau45r/1/