Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

How to solve $ is not defined

pillaivinit
Level 3
Level 3

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.

AEM 6.3 jquery
1 Accepted Solution
Suraj_Kamdi
Correct answer by
Community Advisor
Community Advisor

@pillaivinit 

First thing, Jquery should always load before the execution of your code.

Second thing, It happens mainly because of your clientlib category /dependencies order.

View solution in original post

5 Replies
asutosh_jena
Community Advisor
Community Advisor

@pillaivinit You need to make sure the jquery is defined before this line of code is executed.

pillaivinit
Level 3
Level 3
Sorry If I don't underdstand this I'm new. Can you please elaborate on how can I make sure it is defined?
asutosh_jena
Community Advisor
Community Advisor
Please make sure to include the jquery plugin on the head section and your JS code should be loaded in the footer section.
Anudeep_Garnepudi
Community Advisor
Community Advisor

Hi @pillaivinit 

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 

Suraj_Kamdi
Correct answer by
Community Advisor
Community Advisor

@pillaivinit 

First thing, Jquery should always load before the execution of your code.

Second thing, It happens mainly because of your clientlib category /dependencies order.

View solution in original post