Hello I have a dynamic web table and I want to count the hyperlinks in the table using Javascript.
Here is the HTML:
<tbody>
<tr>
<td style="..."
<a id =" " href="test1">123456</a>
</td>
<td style="..."
<a id =" " href="test2">123477</a>
</td>
<<td style="..."
<a id =" " href="test3">1234557</a>
</td>
I want to get the count of the href from this HTML
This is what i have tried so far:
Function Rowcount(){
var totalRowCount=0;
//identifying the table
var table=document.getElementById("tableID");
//identifying the row
var rows=table.getElementsByTagName("tr");
var tdata=null;
for( var i=0; i<rows.length; i++){
tdata=rows[i].getElementsByTagName("td")
}
}
I am not understanding how should I refer to "href"
You want to count all A tags inside the table?
Do something like
const table = document.getElementById("tableID");
const total = table.querySelectorAll('a').length;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With