where to write javaScript for a component such that if two components are used on same page ,it didn't conflict in AEM as a cloud service
Hi, Currently I am writing my javaScript code inside my html only
for e.g :
-> if my component name is "cmp1" then I am writing my js code inside cmp1.html
->if there are two components on the same page my js of cm1 is conflicting with cm2
-> e.g. : I am creating div tag in each js , and accessing some elements , but the problem arises when there are more than one components on page, then my js code conflicts because it is same of the component.
-> I want to know what is the correct way to write js for component if it is to be used more than one time on page
-> and what best practices I can follow
The js runs when the website loads and component is present on the page
Please help me out
thank you
Rahul