Count number of li element and addclass
6
I am trying to count LI elements, and addclass to another div. For example,
$('.box2').addClass(function(){
return 'list' + $(this).find('.box1 li').length;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="box1">
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
<div class="box2">text</div>
This should be like this <div class="box2 list3">text</div> But I don't know why when I check on the DOM code, <div class="box2 list0">text</div> I get this result. What do I need to fix the code? Please help.
...