Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 232
lorenzoid Avatar asked Feb 27 '26 13:02

lorenzoid


1 Answers

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)

like image 91
Ming Chan Avatar answered Mar 01 '26 01:03

Ming Chan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!