coderex coderex - 3 months ago 17
Javascript Question

How to count the number of anchor tags within a div using javascript?

I want to know how to count the number of anchor tags present within a

div
element.
e.g.:

<div>
<a href="1" >1</a>
<a href="2" >2</a>
<a href="3" >3</a>
<a href="4" >4</a>
</div>


How many
<a>
tags?

Answer
theDivElement.getElementsByTagName('a').length