简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM