Follow Along as I Stumble on the Path to Learning RoR

Loading Javascript After Page Load

If the script loads too early and it’s looking for elements on a page, it can generate an error sometimes. To correct that, you can add lines to your script to load after the page is done loading (so it can find the required elements).

If it’s just javascript, you can add:
function afterLoad(){

like so:

function afterLoad(){

If you’re using jQuery, you can add (with your script between the brackets):
jQuery(document).ready(function($) {


Comments are closed.