How set Parent element for backbone view ?
var TodosView = Backbone.View.extend({
tagName: 'p', // required, but defaults to 'div' if not set
className: 'container', // optional, you can assign multiple classes to
// this property like so: 'container homepage'
id: 'todos', // optional
initialize: function(){
// debugger
this.$el.html("bamboo4a")
$("body").append(this.$el);
}
});
var todosView = new TodosView();
I do not want to write $("body").append
For the main view you can set the view element when creating the view object by passing the options to its constructor (namely the option el).
var MyView = Backbone.View.extend({
template: '<p>Hello World!</p>',
render: function() {
this.$el.html(this.template);
}
});
new MyView({
el: 'body' // or el: '#content' and so on
}).render();
Documentation
Demo
Demo with more detailed example of the application
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