-
Is there a way to use jquery AND "turbo:load" ? With turbo:load "simulating" a SPA, scripts are only exceuted on the first page load. My jQuery scripts work, if I reload the page where I want the script to be executed. The docs mentions document.addEventListener("turbo:load", which works really well btw, but i'd have to rewrite everything in vanilla JS. Is there another way so I can use my jQuery scripts whenever I navigate on a page ? Thanks again for the awesome work ! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi @sylzys, you can use jQuery inside an event or call it there: document.addEventListener("turbo:load", () => {
$( "button.continue" ).html( "Next Step..." )
}) There is a big difference only with load events such as $ (document) .ready (function () {
console.log ("ready!");
}); They should be changed to a turbo call.
But you can still use any library or framework like Vue / React, and the only point is the initialization process is tied to the turbo event. |
Beta Was this translation helpful? Give feedback.
-
It's working now thanks @tabuna :) |
Beta Was this translation helpful? Give feedback.
-
OMG! I was wandering around feeling utterly hopeless, trying to figure out why my JavaScript wasn't working after encountering validation errors in React inputs. But then, a stroke of luck! I stumbled upon the solution: by embedding my JavaScript code into Turbo, everything started working smoothly. @tabuna , this definitely needs to be documented. Blessings on your work |
Beta Was this translation helpful? Give feedback.
Hi @sylzys, you can use jQuery inside an event or call it there:
There is a big difference only with load events such as
They should be changed to a turbo call.
But you can still use any library or framework like Vue / React, and the only point is the initialization process is tied to the turbo event.