I have the following template:
<div class="row">
<div></div>
....
</div>
and the following view:
var TestView = Backbone.View.extend({
tagName: "div",
template: $("#tests_template"),
initialize: function () {
_.bindAll(this, 'clickbtn');
},
events:
{
"click .btn": "clickbtn"
},
render: function () {
....
{
});
The problem is, it produces the following output:
<div><div class="row">...</div></div>
How do I get rid of the outer div? I tried removing the tagName property from the view but it still puts a div?
Change your template to get rid of the outer div:
Then, tell the view to create the div with a class name:
OR if you want to keep the current template, then tell the View which
elto use (assuming it exists already some place on your page):EDIT You asked if you can do this in the initializer? Sure, but you’d need to make sure that you hook the events:
Honestly, though, the first two options are more de-coupled IMO.