I am trying to toggle the opacity of a DOM element on an event which is attached to a javascript method. A click on checkbox is what triggers the completed
method.
The below method is triggered on a click:
completed: function(){
var task = this.$('.actions');
console.log(task);
if(!task.hasClass('toggle')){
task.addClass('toggle');
} else {
task.removeClass('toggle');
}
}
}
The CSS
.toggle{
opacity: 0.4;
}
and the HTML (underscore template, in this case) is
<div class="table table-bordered">
<div class="actions">
<input type="checkbox" class='completed'>
<button type='button' class='delete btn btn-danger btn-xs'> x </button>
<button type='button' class='edit btn btn-primary btn-xs' id='actions'> edit </button>
<span style='font-weight:bold' class="word" spellcheck='false'> <%= task %>-</span>
<span class="definition" spellcheck='false'> <%= description %> </span>
</div>
</div>
But nothing happens. How can I addClass to a DOM element via javascript?