Thursday, February 16, 2012

Javascript/jquery count li elements inside ul

Below is the script with which you can get the count of li present in ul..


Html::

<ul id="myulid">
  <li>List Item1</li>
  <li>List Item2</li>
  <li>List Item3</li>
  <li>List Item4</li>
  <li>List Item5</li>
</ul>

Java Script:: 


<script type="text/javascript">
var myul = document.getElementById('myulid');
var liCount= myul.getElementsByTagName('li').length;
alert(liCount);
</script>


Hope this helps...

No comments:

Post a Comment

Popular Posts