Find row and column of clicked table cell in JavaScript without jQuery

I am trying to create an onclick function that returns the row and column of a clicked cell from a table in JavaScript without using jQuery. I will still return the column, but I cannot figure out how to get it to return a row.

  **cellToAppend.addEventListener("click", clicked);**

  **function clicked() {
    alert("clicked cell at: " + (this).cellIndex + ", ");
  }**
+4
source share
1 answer

Use parentNodeto get a string.

function clicked() {
    alert("clicked cell at: " + this.cellIndex + ", " + this.parentNode.rowIndex);
}
+5
source

All Articles