isSameNode
In this chapter you will learn:
Compare the nodes
isSameNode
method compares objects that
you have obtained from different queries.
<!DOCTYPE HTML> <!--from j a v a2s . c o m-->
<html>
<body>
<table>
<tbody id="SurveysBody">
<tr id="myRow"><td>A</td><td>B</td></tr>
</tbody>
</table>
<pre id="results"></pre>
<script>
var elemByID = document.getElementById("myRow");
var elemByPos =
document.getElementById("SurveysBody").getElementsByTagName("tr")[0];
if (elemByID.isSameNode(elemByPos)) {
document.getElementById("results").innerHTML =
"Objects are the same";
}
</script>
</body>
</html>
Compare two table rows
The following code compares two rows in a table.
<!DOCTYPE HTML> <!-- j a v a 2 s .co m-->
<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>
Next chapter...
What you will learn in the next chapter: