Ashkan Mobayen Khiabani Ashkan Mobayen Khiabani - 6 months ago 15
jQuery Question

How to know if two jquery objects are pointing to the same element

The code below alerts


var a = $('html');
var b = $('html');

Is there a way to know if two variables are pointing to the same element?


Using the normal equality operators (ie. == and ===) doesn't work for objects. However, you can use the is() method to compare two jQuery objects, like this:

var $a = $('html'); 
var $b = $('html'); 

if ($$b)) {
} else {
  console.log('not the same');
<script src=""></script>