
Get the li count of a specific ul in javascript
I want to get the count of all LI (List item) of a specific UL in Javascript. How can i get the count of the all list item by targeting an unordered list of HTML.
Answers 1
-
<ul id="ul_list"> <li>Lorem ipsum dolor sit amet consectetuer.</li> <li>Aenean commodo ligula eget dolor.</li> <li>Aenean massa cum sociis natoque penatibus.</li> </ul> <script> var listCount = document.getElementById("ul_list").getElementsByTagName("li").length; alert(listCount); </script>
0It will return the count of all (LI) items of an UL.
Random Code Snippet Queries: Javascript
- How to check caps lock is on in javascript
- ReferenceError: Cannot access 'myFunction' before initialization
- Cropper js with multiple images
- Javascript get data-id attribute value
- Javascript to print Fibonacci series upto 15 Observations
- Input type file styling
- Uncaught SyntaxError: Identifier 'CODE' has already been declared
- Remove hostname from URL in javascript
- How to echo array in Javascript
- Get hostname from URL in javascript
- How to get the length of a number in JavaScript
- How to Set data to localstorage in javascript
- ReferenceError: $ is not defined
- JavaScript test() Method
- How to crop multiple images with cropper js
- How to show and hide placeholder text
- How to check file is an image in javascript using filename
- How to set href value of anchor tag in javascript
- Short-circuits conditionals
- How to fixed bootstrap navbar at top on scroll
- How can I add a key/value pair to a JavaScript object
- Copy one array to another in javascript
- Trim the leading and trailing comma from string in Javascript
- On click enter redirect to another URL with parameters in javascript
- How to open modal after redirect