Running jQuery before jQuery is called

Hi there,

Is it possible to run a jQuery line before jQuery is called?

I have the following line which I am ttrying to run:


It works in console, but when I add it to a JS file, it doesn’t work.

I am using a WordPress website and using the WordPress enqueue function to insert the JS file, but it appearing before the actual jQuery library.

Is there anyway to run it before the jQuery library line?


Nope. You can’t run that line until the jQuery library is loaded.

You have to specify jQuery as a dependency to ensure the scripts are getting loaded in the correct order:

wp_enqueue_script('myscript', './path/to/myscript.js', ['jquery']);
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.