Google News
logo
Backbone - Interview Questions
Why is it not recommended to change the "el" property of a view directly?
It is not recommended to change the "el" property of a view directly because when you attempt to change the "el" property directly, it may lead to inconsistent behavior from the Backbone.js view. The reason behind this inconsistent behavior is that when you change the "el" property directly, it doesn't automatically update the cached jQuery object property corresponding to it, which is "$el".
 
The correct way to do this is to use "setElement()" on the view.
 
Syntax :
view.setElement(otherElement) 
 
Advertisement