lorenzoid
lorenzoid

Reputation: 1832

Backbone - this.$el vs $(this.el)?

I've been using this.$el all over my backbone app like so:

render: function() {
    this.$el.html(this.template);
},

then I saw code online that uses:

render: function() {
    var dict = this.model.toJSON();
    var html = this.template(dict);
    $(this.el).append(html);
}

What is the difference between the two?

Upvotes: 3

Views: 2180

Answers (1)

Ming Chan
Ming Chan

Reputation: 1958

If you call $(this.el), your just keep executing the jquery selector to get the same jquery object. '$el' is the cached version of $(this.el)

Upvotes: 6

Related Questions