Compare ‘’ to a jQuery object

What I want to do:

( clickedObject === someDiv ) //returns true or false

What I tried

( $( === $('.selector') ); //returns a false negative.

My workaround

( $('class') === $('.selector').attr('class') ); //works as intended, not so clean though.

What is the right way to compare the object I clicked to an object in the DOM?


To check if has this class you can use the hasClass function.

if ($("selector"))

Or, if you really want to compare objects, note that jQuery selectors return a collection of items, so I think you’ll want

if ( === $('.selector')[0])

Leave a Reply

Your email address will not be published. Required fields are marked *