Garfield
Garfield

Reputation: 1222

understanding jquery closest()

I'm looking at this plugin and trying to understand how the _handle_mousedown event works.

It uses the expression: $(event.target).closest(that.element).is(that.element)

It seems to me that the .closest(that.element).is(that.element) should always return true as that.element should always be the same as itself.

What am I missing?

Upvotes: 1

Views: 60

Answers (1)

Dave
Dave

Reputation: 10924

This seems to be a way to check for the existence of an element.

The code you posted:

$(event.target).closest(that.element).is(that.element)

Is equivalent to the following:

$(event.target).closest(that.element).length === 1

Upvotes: 2

Related Questions