Reputation: 8274
Within a click function, I have the below code:
home.addEventListener('click', () => {
myAPP.mapview.map.layers.items.forEach(item => {
item.visible = false;
});
//........... }
However, after the button is clicked once, it seems to continuously run/execute. How could I assure it executes, i.e. 'resets' just one time, just when the button or click function occurs?
Upvotes: 1
Views: 240
Reputation: 605
The problem you are having is that multiple dom elements are firing the same click event at the same time. You should have the following:
home.addEventListener('click', (e) => {
// to prevent child/parent dom elements from firing the same event.
if( e.target !== this ) {
return;
}
});
Upvotes: 1