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 :)
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
Hi Naziya,
Are you using any JavaScript Code on OnReady screen event? or using any component which uses JS.
Hi Shubnam,
Yes, JS is used.
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,
Hi Mukul,
The event is "OnParameterChange"
Here is the JS code used
Hi,
It is advised by OutSystems not to use jQuery ($). You could consider to refactor the code into vanilla javascript.
-- Daniel
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.classList.add("selected-choice");
I'm getting this error after changing the script.
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.
Thankyou Paulo it worked :)