Backbone - this.$el vs $(this.el)?
Asked Answered
P

1

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?

Pereyra answered 25/9, 2013 at 19:26 Comment(1)
The docs are pretty clear on what $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.Roemer
L
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)

Laris answered 25/9, 2013 at 20:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.