jquery - Use Javascript in Rails -
i started learn javascript , want use in rails. javascript code simple, experiment:
var pagealert = function(){ alert("this working");} $('#refresh-button').on('click',pagealert);
i must put code in "application.js" file , inside function
$(document).ready(function(){...});
otherwise, won't work. example, if put in "custom.js" or in "application.js" outside document.ready function, not working. assume don't have put inside document.ready function. know concept of asset pipeline, , in "application.js", have default
//= require_tree .
this should easy, can't figure out. suggestion or tutorial on this? thanks.
you can put code function declarations , basic javascript outside $(document).ready(function(){...});
block. try example write alert("hello world")
.
however $(document).ready(function(){...});
first triggered when dom loaded, ie. when browser have downloaded html , ready render page. if call javascript functions manipulate dom $('#refresh-button')
outside of ready
block, code runned before dom ready, , not work because, in example, there no element id refresh-button
yet.
hope answers question, otherwise feel free ask more information.
Comments
Post a Comment