HTML DOM isEqualNode( ) Method

HTMLWeb DevelopmentFront End Technology

The HTML DOM isEqualNode() method returns a boolean value (true/false) if specified nodes are equal or not.

Syntax

Following is the syntax −

Calling isEqualNode()

firstNode.isEqualNode(secondNode)

NOTE‘firstNode’ and ‘secondNode’ are equal only if they have same type, attributes and attribute values. All childNodes if any should also be the same.

Example

Let us see an example for isEqualNode() method −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>isEqualNode()</title>
<style>
   body{
      width: 90%;
      margin: 0 auto;
   }
   button{
      border-radius:10px;
      display:block;
      margin:0 auto;
   }
   #authorJohn, #authorMaya{
      border:1px solid black;
      border-radius:10px;
   }
   #showContent{
      text-align:center;
   }
</style>
</head>
<body>
<div id="authorJohn">
<h2>
Lorem ipsum dolor
</h2>
<h5>By - John</h5>
<p class="content">
sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</div>
</p>
<div>
<div id="authorMaya">
<h2>
Excepteur sint occaecat
</h2>
<h5>By - Maya</h5>
<p class="content">
sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</div>
</p>
<button onclick="checkPlagiarism()">Check Plagiarism</button>
<div id="showContent"></div>
<script>
   function checkPlagiarism(){
      var articleOne = document.getElementsByClassName("content")[0];
      var articleTwo = document.getElementsByClassName("content")[1];
      var divDisplay = document.getElementById("showContent");
      if(articleOne.isEqualNode(articleTwo))
         divDisplay.textContent = 'Content is copied!'
      else
         divDisplay.textContent = 'Content is not copied!'
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Check Plagiarism’ button −

After clicking ‘Check Plagiarism’ button −

raja
Updated on 30-Jul-2019 22:30:26

Advertisements