For example, I have a page with many text links, image links and button links. Whenever any of them is clicked on this page, I would like the event to be tracked (using a wixWindow trackevent bit of code to send a signal to a Facebook pixel).
It’s painful installing an event handler code for every element on this page…I am sure there must be one bit of code that does the job for ALL clicks on this page.
Hi Naresh,
You can create an array of all IDs and use forEach loop to add an event listener to each event. Here’s an example to better explain what I was referring:
If you want to add a specific set of buttons that you have added consecutively and they are named “button1”, “button2”, etc. you can use a for loop, like so:
**let** tableButtons = [];
**for(let** i = 20 ; i <= 41 ; i ++){
tableButtons . push($w ( "#button" + i ));
}
console . log ( tableButtons );