8/26/2010

How to Count all li elements in an ul tag by javascript

<script type="text/javascript">
var ulId = document.getElementById("ulid");
var totalLi = ulId.children.length;
alert(totalLi);
</script>

The list of the li in ul tag example is


<ul id="ulid">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>

No comments:

Post a Comment