Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting the number of hyperlink in a table

Tags:

javascript

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"

like image 683
TS0306 Avatar asked Nov 24 '25 13:11

TS0306


1 Answers

You want to count all A tags inside the table?

Do something like

const table = document.getElementById("tableID");
const total = table.querySelectorAll('a').length;
like image 107
arieljuod Avatar answered Nov 26 '25 02:11

arieljuod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!