user1781543
user1781543

Reputation: 133

Backbone.js - difference between this.$(selector) and this.$el.find('selector')

As per title, what is the difference (if any) in a backbone view between saying:

this.$('.foo');

and

this.$el.find('.foo');

They both return the element and appear to scope it to the current view but I've seen examples using both methods.

Thanks

Upvotes: 13

Views: 10834

Answers (1)

jevakallio
jevakallio

Reputation: 35890

The difference is precisely none whatsoever. The method in Backbone source code is declared as:

$: function(selector) {
  return this.$el.find(selector);
}

Upvotes: 23

Related Questions