How can we compare two HTML elements whether they are identical or not ?
I tried this thing but no luck
<div class="a"> Hi this is sachin tendulkar </div>
<div class="a"> Hi this is sachin tendulkar </div>
And then on button click, I call a function check()
var divs = $(".a");
alert(divs.length); // Shows 2 here which is correct
if (divs.get(0) == divs.get(1)) alert("Same");
But this is not working. Everything is same in two divs.
Apart from this How can we compare whether two HTML elements are completely idential or not.
Including their innerHTML, className, Id, and their attributes.
Is this doable ?
Actually, I have two HTML documents and I want to remove the identical content from both of them So two elements can have same id.
PS: Updating after Crowder's valuable comments.
If we compare two elements as strings, we would not get a match as their order of attributes may vary So the only option is to iterate through each child attribute and match. I still have to figure out completely working implementation strategy.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…