What is the difference between $el and el in Backbone.js views?

ali asad picture ali asad · May 20, 2013 · Viewed 32.2k times · Source

Can you please tell the difference between $el and el in Backbone.js views?

Answer

Rayweb_on picture Rayweb_on · May 20, 2013

lets say that you do this

var myel = this.el; // here what you have is the html element, 
                    //you will be able to access(read/modify) the html 
                    //properties of this element,

with this

var my$el = this.$el; // you will have the element but 
                      //with all of the functions that jQuery provides like,
                      //hide,show  etc, its the equivalent of $('#myel').show();
                      //$('#myel').hide(); so this.$el keeps a reference to your 
                      //element so you don't need to traverse the DOM to find the
                      // element every time you use it. with the performance benefits 
                      //that this implies.

one is the html element and the other is the jQuery object of the element.