I have a list
<ul>
<li>
<li>
<li>
...
</ul>
I need jQuery to count the number of items in my list.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
.length, like this:.lengthtells how many matches the selector found, so this counts how many<li>under<ul>elements you have…if there are sub-children, use"ul > li"instead to get only direct children. If you have other<ul>elements in your page, just change the selector to match only his one, for example if it has an ID you’d use"#myListID > li".In other situations where you don’t know the child type, you can use the
*(wildcard) selector, or.children(), like this:or: