내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

How to solve $ is not defined

Avatar

Level 4

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.

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Community Advisor

@Vinit_Pillai 

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

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

원본 게시물의 솔루션 보기

6 답변 개

Avatar

Community Advisor

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

Avatar

Level 4
Sorry If I don't underdstand this I'm new. Can you please elaborate on how can I make sure it is defined?

Avatar

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.

Avatar

Community Advisor

Hi @Vinit_Pillai 

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 

Avatar

정확한 답변 작성자:
Community Advisor

@Vinit_Pillai 

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

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

Avatar

Level 1

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:

  • Conflict with Other Libraries
  • Path to your library included is not correct
  • Llibrary file is corrupted
  • Working offline (when you use CDN)