You will have to update your class
manually after the render
method. Backbone initializes the className
of the element of your View only once time during the _ensureElement
method:
_ensureElement: function() {
if (!this.el) {
var attrs = _.extend({}, _.result(this, 'attributes'));
if (this.id) attrs.id = _.result(this, 'id');
if (this.className) attrs['class'] = _.result(this, 'className');
var $el = Backbone.$('<' + _.result(this, 'tagName') + '>').attr(attrs);
this.setElement($el, false);
} else {
this.setElement(_.result(this, 'el'), false);
}
}
If you take a look it has a check in case of the element already exists.
Anyway, you can do that manually in your render
method:
render: function(){
//Your logic
this.$el.attr('class', _.result(this, 'className'));
}