isSameNode
isSameNode method compares objects that you have obtained from different queries.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<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 following code compares two rows in a table.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<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>
Home
JavaScript Book
DOM
JavaScript Book
DOM
HTMLElement:
- The HTMLElement Members
- element tag name, id, direction, language, hidden disabled information
- addEventListener
- appendChild
- attributes returns a collection containing all of the attributes
- classList
- className
- cloneNode
- createElement
- createTextNode
- dataset
- getAttribute
- getElementsByTagName
- hasAttribute
- innerHTML
- insertAdjacentHTML
- insertBefore
- isSameNode
- outerHTML
- onmouseout
- onmouseover
- querySelectorAll
- removeEventListener