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

How to solve $ is not defined

Avatar

Avatar
Validate 10
Level 1
pillaivinit
Level 1

Likes

0 likes

Total Posts

30 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Applaud 5
Affirm 1
View profile

Avatar
Validate 10
Level 1
pillaivinit
Level 1

Likes

0 likes

Total Posts

30 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Applaud 5
Affirm 1
View profile
pillaivinit
Level 1

20-12-2020

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Seeker
MVP
Suraj_Kamdi
MVP

Likes

148 likes

Total Posts

159 posts

Correct Reply

42 solutions
Top badges earned
Seeker
Bedrock
Engage 1
Springboard
Validate 1
View profile

Avatar
Seeker
MVP
Suraj_Kamdi
MVP

Likes

148 likes

Total Posts

159 posts

Correct Reply

42 solutions
Top badges earned
Seeker
Bedrock
Engage 1
Springboard
Validate 1
View profile
Suraj_Kamdi
MVP

21-12-2020

@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.

Answers (2)

Answers (2)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct Reply

206 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct Reply

206 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

20-12-2020

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

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

20-12-2020

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