Search code examples
google-chromedhtml

Row Index -1 result in Safari and Chrome


Why I get Row Index -1 result in Safari and Chrome when I try to access a dynamic created table row?

The row is appended with document.getElementById('tabl').appendChild(rowobject) and then gets the value of -1 to row Index. Can I fix this somehow?


Solution

  • When referencing the active/selected row in a table, an index of -1 means there is currently no active/selected row. When searching for the row index of a table by the content of some field, a search result of -1 means no such row was found.

    This is because tables are 0 index based - meaning the first row is row 0, the second row is row 1, etc. -1 refers explicitly to no row / an invalid row.