I’m not very good with js, but basically I have a button
<%=button_to_function "✓", checkButton(), :class => "buttonGrey"%>
that is calling a js function I made. However I am getting errors in my syntax for the function.
function checkButton()
{
if (this.className="buttonGrey") {
this.removeClass('buttonGrey');
this.addClass('buttonGreen');
}
if (this.className="buttonGreen") {
this.removeClass('buttonGreen');
this.addClass('buttonGrey');
}
}
Use
==to comparestringsand not=.Your button will always be
buttonGreybecause if it changes on the firstifstatement, it will be changed again on the second because it’s not inside aelsestatement.Also you can use
toggleClassto toggle classes.