Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Let I have a button <button type="button" onclick = "myfunction()" class="collapsible">Expand content</button> And, I have a JS function. function collapse() { var coll = docu...
#1: Initial revision
How to call a function from ruby-on-rails (HTML)?
Let I have a button ```html <button type="button" onclick = "myfunction()" class="collapsible">Expand content</button> ``` And, I have a JS function. ```javascript function collapse() { var coll = document.getElementsByClassName("collapsible"); var i; for (i = 0; i < coll.length; i++) { coll[i].addEventListener("click", function() { this.classList.toggle("active"); var content = this.nextElementSibling; if (content.style.display === "block") { content.style.display = "none"; } else { content.style.display = "block"; } }); } } ``` Usually, we call a JS function in HTMl using `onclick`. What if it comes to Ruby-on-rails? I noticed that I can't call a function that way in Ruby-on-rails. How to call a function from ruby-on-rails (HTML)?