tags:

views:

47

answers:

2

How may I check if 2 Dom element are same.

Form example

var element1 = document.getElementById("abc");
var element2 = document.getElementById("abc");

Now how should I chekc that these 2 elements are equal?

Thanks

+1  A: 

element1 and element2 are references to the same place in the DOM tree. Just check

if( element1 == element2 )
{
  alert("same") ;
}
bobobobo
+2  A: 

If the Ids are the same, they cannot be different. If the Ids are different they cannot be the same. So if you have both Ids you can just compare the two Ids.

Ilya Boyandin
The `id` attribute of two elements __shouldn't__ be the same. But people do weird things..
bobobobo