Skip to content Skip to sidebar Skip to footer

Loading Javascript With Turbolink Plugin

I know there is jQuery-turbolinks. But is there anyway to use jQuery and JS with turbolink. https://github.com/rails/turbolinks With Turbolinks pages will change without a full rel

Solution 1:

You can do the following to run your javascript on both page:load and ready.

$(document).on('page:load ready', function() {
    ...
});

Solution 2:

Try it out ;)

var ready;
ready = function() {
  $(function() {
    return $('.status').hover(function(event) {
      return $(this).toggleClass("hover");
    });
  });
};
$(document).ready(ready);
$(document).on('page:load', ready);

Solution 3:

This doc showing how to: https://github.com/turbolinks/turbolinks

document.addEventListener("turbolinks:load", function() {
      // ... Your code here!
    })

Post a Comment for "Loading Javascript With Turbolink Plugin"