Rails 4.2.2
gem turbolinks
//= require turbolinks
I have had success using $(document).on('page:change', function () { // });
but this script is being difficult. I do not use the jquery-turbolinks gem.
Unlike other scripts in my app, it will not work if I place it inside of the
assets/javascripts
folder. It only works if the script is placed in thehtml.erb
view file.It works correctly only the first time. Meaning, I want it run and then run again assigning new variable values, because all of the variable values will change after it is run the first time. Instead, when the function is initiated a second time (by clicking on
var craw = $('.glyphicon-chevron-right').last()
) it acts like it is being clicked on for the first time and adds the same page again and opens the same modal again because the variable values have not been updated.$(document).on('page:change', function () { var xyz = $('.nextinst').last().attr('href') var mod = $('.modal'+xzy) var turn = $('.pagination .next_page a').attr('href') var craw = $('.glyphicon-chevron-right').last() $(craw).on('click', function() { if (!$(mod).size() > 0) { $.getScript(turn); } setTimeout (function() { $(xyz).modal() }, 1000); }); });