/

HTML / CSS / JavaScript Tutorial

JavaScript tr object property: rowIndex

[this page | pdf | back links]

The rowIndex property of the JavaScript DOM object corresponding to the HTML <tr> element sets / returns the position of a row in the rows collection of a <table> element.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,td,tr,caption {border: thin solid black; border-collapse: collapse;}
</style>
</head>
<body>
Table row objects support insertCell() and deleteCell() methods, but
the precise cells inserted or deleted can vary according to browser<br><br>
<span id="element"></span>

<script>
var x = document.createElement("TABLE");
var y0 = x.insertRow(0);
var y00 = y0.insertCell(0);
var y1 = x.insertRow(1);
var y10 = y1.insertCell(0);
y00.innerHTML = "row" + y0.rowIndex;
y10.innerHTML = "row" + y1.rowIndex;
document.getElementById("element").appendChild(x);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile