As I add and remove a class by making click on a row


#1

hello as I add and remove a class by making click on a row.

Template.offerRooms.events({

‘click .room-tbody tr’: function(event){
event.preventDefault();
$(event.target).addClass(‘selected’);
},
‘click .selected’: function(event){
console.log(“se quita”);
$(event.target).removeClass(“selected”);
}


#2

It’s very hard to figure out what you’re trying to say. Can you try to rephrase the question?


#3

sure, what I try to do is that when you click in a row a class is added to td, but if I click again the class is removed.

thanks for your help and forgive the language


#4

hello, solve it so

‘click .room-tbody tr td’: function(event){
event.preventDefault();
if ($(event.target).hasClass(“reserved”)) {
console.log(“esta esta registrada”);
} else if($(event.target).hasClass(“selected”)) {
$(event.target).removeClass(‘selected’);
} else {$(event.target).addClass(‘selected’); }
}


#5

Ok, glad you figured it out!


#6

I dont think you need the event.preventDefault(); because you’re just working on a click event on a table cell.
You only need prevent default when there is some default browser behaviour you want to prevent, like on a form submission or a anchor/URL click…