Right now I am using:
<%=button_to_function "✓", checkButton(), :class => "buttonGrey"%>
But the javascript function needs something to be passed to it so it can toggle the class( I want the buttons class to be changed upon pressing it) What would I pass as a param to represent the button?
Since "button_to_function" is deprecated since Rails 4.0.2, now you can use "button_tag" helper.
Exemple:
Note: If you use CoffeeScript, declare your function as:
because in CofeeScript, functions are not global scoped by default.
Just use straight up jquery.
Inside
checkButton()
, you should be able to accessthis
and manipulate it using jQuery or whatever your framework is.For example, using jquery:
You can execute javascript directly in the button_to_function.
In your case:
<%= button_to_function "✓", '$(this).toggleClass("buttonGrey buttonGreen");', :class => "buttonGrey" %>
Hope this helps!
Use the on click event inside the button tag