The HTML DOM isEqualNode() method checks whether the two nodes are equal or not. These nodes are considered equal if they are of the same type, having the same characteristics and the same attributes. The attributes do not have to be in the same order.
Syntax:
node.isEqualNode(othernode)
Parameters: The “othernode” parameter is required in this function. It is the node that will be compared.
Return Value: Returns a Boolean value, if matches then True else False.
Example: In this example, we will check if the three div elements are equal or not by using the HTML DOM isEqualNode() Method.
html
<h3>Comparing the div elements.</h3>
<div>GeeksforGeeks</div>
<div>GfG</div>
<div>GeeksforGeeks</div>
<button onclick="isequal()">Check</button>
<p id="result"></p>
<script>
function isequal() {
var out = document.getElementById("result");
var divele = document.getElementsByTagName("div");
out.innerHTML += "element 1 equals element 1: " +
divele[0].isEqualNode(divele[0]) + "<br/>";
out.innerHTML += "element 1 equals element 2: " +
divele[0].isEqualNode(divele[1]) + "<br/>";
out.innerHTML += "element 1 equals element 3: " +
divele[0].isEqualNode(divele[2]) + "<br/>";
}
</script>
|
Output:
We have a complete list of HTML DOM methods, to check those please go through this HTML DOM Object Complete reference article.
Supported Browsers: The browser supported by DOM isEqualNode() Method are listed below:
- Google Chrome 1
- Edge 12
- Firefox 1
- Opera 12.1
- Internet Explorer 9
- Safari 3
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
01 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...