Reputation: 12363
I am having a problem the Backbone.js View not rendering. My code is fairly simple and looks like this:
TableView = Backbone.View.extend({
initialize : function() {
this.render();
},
render : function() {
var template = _.template($("#table_template").html(), {});
alert(this.el);
this.el.html('Go');
//this.el.html(template);
},
events: {
},
});
And this is the code for instaniting the object and setting the el
<script type="text/javascript">
$(document).ready(function() {
var t = $("#table_1");
//This works!!!
t.html('Test');
//Passing the element as the el, never works
var table = new TableView({el : t});
});
</script>
Except it always says in the console:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'html' .
Am I doing something wrong here? I'm using Jquery.1.7.2, backbone 0.9.2, underscore 1.3.3 and json2.
Upvotes: 3
Views: 1318
Reputation: 140210
this.el
is an element not a jQuery object. Try $(this.el).html()
or this.$el.html()
Upvotes: 5