[Javascript] number of elements
ryan at ryancannon.com
ryan at ryancannon.com
Thu Mar 31 10:39:45 CST 2005
> Hi!
>
> How to count number of elements (<a>,<div> etc. tags) in a page?
>
> --
> Bye,
>
> Iztok
>
>
You can also count elements by tag name within an a certain element.
html:
<ul id="thisOne">
<li>Hi.</li>
<li>2</li>
</ul>
<ul>
<li>Red Herring</li>
</ul>
Javascript:
thisOne = document.getElementById("thisOne");
items = thisOne.getElementsByTagName("li");
alert(items.length);
output: 2
More information about the Javascript
mailing list