jQuery method chain - Method to get previous method's return value

In this jQuery Method chain

$(SELECTOR1).find(SELECTOR2).doSomethingThatReturnsjQueryObject()

I would like to continue the chain with the return value of $(SELECTOR1), so the outer DOM node itself.

I am looking for the best solution in performance.

Is there a gentle method, or an array-like-object trick to get the last method's return value?

Upvotes: 1

Views: 208

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

In order to tackle this kind of situations .end() was made.

$(SELECTOR1).find(SELECTOR2).end().doSomethingThatReturnsjQueryObject()

DEMO

Upvotes: 1

Related Questions