Declaring var slider too early?

Jer's Avatar


29 May, 2021 02:41 PM

When I try to set

var slider = $(".royalSlider").data('royalSlider');

anywhere in the file, the variable never sets. The console tells me slider is undefine.

If I wait for the page to load completely, then I type var slider = $(".royalSlider").data('royalSlider'); into the console manually, then the variable will be defined as the slider.

What is the right way to set the slider variable?

  1. Support Staff 1 Posted by Dmytro Semenov on 29 May, 2021 08:47 PM

    Dmytro Semenov's Avatar

    You may get instance of the slider only after it's initialized (after $('.selector').royalSlider({ }) method is executed). Which generally happens in jQuery document.ready event.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac