Compare two nodes with isSameNode in JavaScript
Description
The following code shows how to compare two nodes with isSameNode.
Example
<!--from w w w .j ava2 s . com-->
<!DOCTYPE HTML>
<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>
The code above generates the following result.
Javascript Tutorial Check
Check if an element has a certain attribute...
Check the length of a NodeList for a div el...
Check the length of the array returned from...
Find out the difference between innerHTML a...
Parse current document as the function para...
Check if an element has a certain attribute...
Check the length of a NodeList for a div el...
Check the length of the array returned from...
Compare two nodes with isSameNode in JavaSc...
Determine the node type in JavaScriptFind out the difference between innerHTML a...
Parse current document as the function para...