Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.Js - what's the difference between el and $el?

So I've been stuck for the whole afternoon on this problem which I eventually solved. It turned out I was assigning el instead of $el.

What's the difference between the two and when should I use each of them?

like image 237
reach4thelasers Avatar asked May 17 '12 17:05

reach4thelasers


People also ask

What is El in Backbone JS?

el() The Backbone. js View el method defines the element that is used as the view reference. this. el is created from the view's tagName, className, id and attributes properties, if specified.

What does El in Javascript mean?

el is just an identifier and it refers to an element, a DOM element, which is a convention in that library.


1 Answers

Straight from the documentation, $el is:

A cached jQuery (or Zepto) object for the view's element. A handy reference instead of re-wrapping the DOM element all the time.

So, $el is a cached, jQuery (or Zepto) version of el. If you need to use any jQuery or Zepto methods on el, you can simply use $el instead of wrapping el in $() each time.

like image 112
Colin Brock Avatar answered Nov 09 '22 03:11

Colin Brock