3

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?

Ming Chan
  • 1,938
  • 11
  • 21
lorenzoid
  • 1,812
  • 10
  • 33
  • 51
  • 3
    The docs are pretty clear on what [`$el`](http://backbonejs.org/#View-$el) is. Someone using `$(this.el)` learned Backbone in the old days (or learned from a tutorial based on an old version), that's all. – mu is too short Sep 25 '13 at 20:35

1 Answers1

6

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)

Ming Chan
  • 1,938
  • 11
  • 21