How to make a comparison between jQuery objects
In my day to day jQuery programming, I often come across a comparison that would be a lot easier if I could just compare the 2 jQuery objects I have. With this short amount of code, you can!
Assuming your jQuery selectors only holds one DOM element, you can do a comparison like in the example below.
if ($activeListItem[0] == $(this)[0]) {
alert('Objects match!');
};Simply append [0] to the end, to access the first index of the object (very similar to an array).
Comments
No comments yet.
Leave a Comment
Note: Your comment may require approval before it is posted to the site.