Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if two elements are the same

I would suspect this to work at first:

if ($('#element') == $('#element')) alert('hello'); 

But it does not. How does one test if elements are the same?

like image 687
Jonah Avatar asked Aug 13 '09 03:08

Jonah


People also ask

How do you determine if two elements are similar?

Two different elements have similar chemical properties when they have the same number of valence electrons in their outermost energy level. Elements in the same column of the Periodic Table have similar chemical properties.

How do you check if two values are the same in HTML?

Use the equality (or inequality) or strict equality (or strict inequality) operator to compare two values. To check whether a value is a valid number, use isNaN( ) .

Is jquery a selector?

The is( selector ) method checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector. If no element fits, or the selector is not valid, then the response will be 'false'.


2 Answers

As of jquery 1.6 you can now simply do:

$element1.is($element2) 
like image 71
chrisarton Avatar answered Oct 15 '22 23:10

chrisarton


This should work:

if ($(this)[0] === $(this)[0]) alert('hello'); 

so should this

if (openActivity[0] == $(this)[0]) alert('hello'); 
like image 31
epascarello Avatar answered Oct 15 '22 23:10

epascarello