I have a list
<ul>
<li>
<li>
<li>
...
</ul>
I need jQuery to count the number of items in my list.
I have a list
<ul>
<li>
<li>
<li>
...
</ul>
I need jQuery to count the number of items in my list.
You can use Element.childElementCount
ref: https://developer.mozilla.org/en-US/docs/Web/API/Element/childElementCount
let count = ThatParentElement.childElementCount;
What if you are using this to determine the current selector to find its children
so this holds: <ol> then there is <li>s under how to write a selector
var count = $(this+"> li").length; wont work..
You can do this using jQuery:
This method gets a list of its children then counts the length of that list, as simple as that.
$("ul").find("*").length;
The find() method traverses DOM downwards along descendants, all the way down to the last descendant.
Note: children() method traverses a single level down the DOM tree.