I'm trying to do something deceptively simple -- adding a class to the active backbone element. The code I want to use is:
this.$el.addClass('classIWant');
However, this doesn't work all the time. Sometimes it seems to, but not all the time. However, this always works.
var id = this.$el.attr('id');
$('#' + id).addClass('classIWant');
Obviously I don't want the second example, as it relies so heavily on HTML and the DOM. Is there any reason why the first shouldn't work, or am I missing something else?