In This Javascript Tutorial we will See How To Get And Show Html Table Rows And Cells Index In Row Click Event Using JS And Netbeans Editor .

Subscribe :

Project Source Code:

<!DOCTYPE html>
        <title>Get HTML Table TR And TD Index</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
            td:hover{background-color:#ddd;;cursor: pointer}
            .selected{background-color: red;color: #fff;font-weight: bold}
        <table id="table" border="1">
                <th>First Name</th>
                <th>Last Name</th>
                <td class="selected">LN3</td>
            var table = document.getElementById("table"),rIndex,cIndex;
            // table rows
            for(var i = 1; i < table.rows.length; i++)
                // row cells
                for(var j = 0; j < table.rows[i].cells.length; j++)
                    table.rows[i].cells[j].onclick = function()
                        rIndex = this.parentElement.rowIndex;
                        cIndex = this.cellIndex+1;
                        console.log("Row : "+rIndex+" , Cell : "+cIndex);

#js #javascript

How To Get HTML Table Row And Cell Index Using Javascript [ with Source code ]
30.55 GEEK