188
Views
10
Comments
Solved
$ is not defined
Application Type
Reactive

I had updated the OS UI to the latest version, and I'm getting the error as "$ not defined" in browser 


I checked in error logs too I just got the above message mentioned.



Please help me to solve this :)

Edited by a moderator on 23 Apr 2024 at 11:29
2022-05-02 13-50-49
Paulo Ritto
Solution

Hi @Naziya Anjum

Your original code in jQuery is not fetching the element by Id but fetching it based on the 'data-id' attribute value (at least it seems like it). 

I suggest following Daniel's advice and passing your jQuery code to vanilla JS, something along these lines: 

let elem = document.querySelector('[data-id="' + $parameters.dataid + '"]');

Then you can add the class X to your element by doing:

elem.classList.add('X');

---------------------------------------------------------------------------------------------------------------------

Take a look at the following example (adding class ABC to the element that has the attribute aria-hidden = "true"), adapt it to your case:


Cheers,

Paulo

2025-08-13 09-41-37
Shubham Sharma
Champion

Hi Naziya,

Are you using any JavaScript Code on OnReady screen event? or using any component which uses JS.

2023-12-11 08-31-41
Naziya Anjum

Hi Shubnam,

Yes, JS is used.

2024-07-09 07-02-02
Mukul Singh Nathawat

Hi Naziya,

It looks like the issue is in the Js that you are using. could you share the js and the the screen event on which you are triggering the Js. This error usually occurs when attempting to access variables or identifiers that are not declared or do not exist within the current scope. 


Regards,

2023-12-11 08-31-41
Naziya Anjum

Hi Mukul,

The event is "OnParameterChange"

Here is the JS code used

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

It is advised by OutSystems not to use jQuery ($). You could consider to refactor the code into vanilla javascript.

-- Daniel

2024-07-09 07-02-02
Mukul Singh Nathawat

Hi Naziya,

It looks like you are trying to add and remove a class from a div using js. could you update the js as:


for javascript1

ele = document.getElementById($parameters.dataid);

ele.classList.remove("selected-choice");

for javascript3

ele = document.getElementById($parameters.dataid);

ele.classList.add("selected-choice");


Regards,

2023-12-11 08-31-41
Naziya Anjum

I'm getting this error after changing the script.

2024-07-09 07-02-02
Mukul Singh Nathawat

check the div id that you are passing in the Js. it looks like the div is either not available at the screen/block or the value you the passing in the js i.e. div.id is empty. 

2022-05-02 13-50-49
Paulo Ritto
Solution

Hi @Naziya Anjum

Your original code in jQuery is not fetching the element by Id but fetching it based on the 'data-id' attribute value (at least it seems like it). 

I suggest following Daniel's advice and passing your jQuery code to vanilla JS, something along these lines: 

let elem = document.querySelector('[data-id="' + $parameters.dataid + '"]');

Then you can add the class X to your element by doing:

elem.classList.add('X');

---------------------------------------------------------------------------------------------------------------------

Take a look at the following example (adding class ABC to the element that has the attribute aria-hidden = "true"), adapt it to your case:


Cheers,

Paulo

2023-12-11 08-31-41
Naziya Anjum
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.