I have a js function using $ in it.
My function uses $get(). and works fine when this function is called from HTL but if I add the function in document.load
$(document).load(function () { alert("alert"); });
then I get $ is not defined in console.
Only the function which is called in HTL(Sightly) works.
I'm using AEM 6.3.
Solved! Go to Solution.
Views
Replies
Total Likes
First thing, Jquery should always load before the execution of your code.
Second thing, It happens mainly because of your clientlib category /dependencies order.
@Vinit_Pillai You need to make sure the jquery is defined before this line of code is executed.
In the page where you are getting error, right click on the page and click view source and in source search(Ctrl+F) for jquery. Make sure that jquery loads in head section of your page.
document. is Javascript and will work without error
$(document). $ is jquery framework, we should load it before using it on page.
-AG
First thing, Jquery should always load before the execution of your code.
Second thing, It happens mainly because of your clientlib category /dependencies order.
If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means ‘x’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘x’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘x’.
To solve this error: Load your library at the beginning of all your scripts.
There can be multiple other reasons for this issue:
Views
Likes
Replies