Compare two table rows in JavaScript

Description

The following code shows how to compare two table rows.

Example


<!--from www.j  a v  a  2  s  .co  m-->
<!DOCTYPE HTML>
<html>
<body>
<table>
<tbody>
<tr class="myRow"><td>Plum</td><td>Purple</td></tr>
</tbody>
</table>
<table>
<tbody>
<tr class="myRow"><td>Plum</td><td>Purple</td></tr>
</tbody>
</table>
<pre id="results"></pre>
<script>
var elems = document.getElementsByClassName("myRow");
if (elems[0].isEqualNode(elems[1])) {
document.getElementById("results").innerHTML = "Elements are equal";
} else {
document.getElementById("results").innerHTML = "Elements are NOT equal";
}
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Compare two table rows in JavaScript
Home »
  Javascript Tutorial »
    Tag »
      Table
Javascript Tutorial Table
Add new row to a HTML table in JavaScript
Change table structure with outerHTML in Ja...
Compare two table rows in JavaScript
Copy table row between two tables using inn...
Remove a row from a HTML table in JavaScrip...