Web Development for 2010

Alexander Dickson - Web Developer covering PHP, jQuery / Javascript, XHTML, CSS, more

How to make a comparison between jQuery objects

Filed under jQuery / JavaScript. Published on Tuesday, 13th October 2009.

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

Comment Details

Your email will never be displayed. If you have a gravatar, it will be displayed.

Note: Your comment may require approval before it is posted to the site.

Stack Overflow Profile

view full profile »

About

I'm a web developer from the Sunshine Coast, Australia. more »