I think I'm fundamentally misunderstanding how to implement Javascript in my rails app. My understanding was that you throw your Javascript into your application.js
file and then you can reference elements in your DOM using jQuery
in order to make an interactive web page.
I just checked through all of my code, and it looks clean (posted below in case I'm wrong). My thought is that I may be putting my Javascript in the wrong place, or I'm missing a dependency somewhere? I found other posts to be mostly unhelpful for me. How do I merge Javascript into my app?
application.js
function main() {
$('.answers-box').hide();
$('.qaa-box').on('click', function() {
$(this).next().slideToggle(400);
});
}
$(document).ready(main());
page.html.erb
<div class=qaa-box>
<h4>Lorem ipsum dolor sit amet, consectetur adipiscing elit</h4>
<p class=answers-box>
Lorem ipsum dolor sit amet, consectetur adipiscing elit
</p>
</div>