Skip to content

Use Jquery + turbo:load for script execution on each page #1861

Answered by tabuna
sylzys asked this question in Q&A
Discussion options

You must be logged in to vote

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.

I would recommend trying to try https://stimulus.hotwired.dev/, which is used as a basis. We also wrote a small example of how you can use this https://orchid.software/en/docs/javascript/

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.

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@sylzys
Comment options

@tabuna
Comment options

@sylzys
Comment options

Answer selected by sylzys
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tabuna
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants