Why do the properties tagName
, id
and className
exist in a Backbone View?
Those properties are used if your view has to create its own element, that is, if it doesn't have a el
attribute when instantiated (various reasons, I can go further in the matter). So you'll have a new element with the id id
, classes className
and attributes attributes
.
You can find the relevant piece of code here. This _ensureElement
method is used in the view's constructor.
All Backbone views have an el property Read doc here.
If you do not pass an el while instantiating a view, it will create an empty DIV
and use it.
Now, just say you do not want to use DIV
as the container to render your view. You want it to be a UL
instead. Just specify the tagName
property for your view and it will be used instead.
If you want to add some css classes to your container, use className
.
If you want to add some attributes to it (For example you want to add data-*
attributes to your el) use the attributes
property of Backbone view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With