I have a rails app. It has this button:
<button class="btn btn-primary" onClick="commentSlide()">Comments</button>
I want the button to change color on the click event, but Rails seems to be having trouble reading my JQuery. The first of the two functions below works. When I remove it, I get this error:
Uncaught ReferenceError: commentSlide is not defined
at HTMLButtonElement.onclick ((index):81)
Here are my two functions. JavaScript works, JQuery does not. Help?
function commentSlide(){
alert("hello");
}
$(document).on('turbolinks:load', function(){
function commentSlide(){
$(this).css('backgroundColor', 'red');
}
})
Here is the top section of my javascript file:
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require react
//= require react_ujs
//= require components
//= require_tree .