My global function is not available because "$ is not a function".
But I do have jquery as a dependency to my own js file:
wp_enqueue_script('common-js', get_stylesheet_directory_uri() . '/js/common.js', array('jquery'), CHILD_THEME_ASTRA_CHILD_VERSION, true);
Why I cannot use jQuery outside of document ready?
2
Answers
try out the below code might help you in achieving the result.
This will create an anonymous function that will be called immediately (
Immediately Invoked Function Expression
orIIFE
) with the$
param and the supplied value for the$
isjQuery
. This way, you make sure that all the code inside this can use$
without polluting the global space