/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> function count(){ var ul = document.getElementById('ulid'); var i=0, c =0; while(ul.getElementsByTagName('li')[i++]) c++; alert(c); } </script> <input type="button" onclick="count()";> <ul id="ulid"> <li>list 1</li> <li>list 2</li> <li>list 3</li> <li>list 4</li> <li>list 5</li> </ul>