I think you misunderstand how setElement
works. When you call setElement
, you're supposed to give it a DOM element that already exists and then setElement
does three things:
- Sets the view's
el
to the element. - Undelegates the events from the old
el
and binds the view's events to the newel
. - Caches a jQuery wrapped version of
el
in$el
.
You seem to be calling setElement
to try to create a new element with id="simpleview"
. You probably just want to include id: 'simpleview'
in the view definition since
this.el
is created from the view'stagName
,className
,id
andattributes
properties, if specified. If not, el is an emptydiv
.
You should get what you're looking for if your view looks more like this:
SimpleView = Backbone.View.extend({
id: 'simpleview',
initialize: function(){
this.render();
},
render: function(){
this.$el.appendTo('#container');
}
});
Updated fiddle: http://jsfiddle.net/ambiguous/7GPEy/