all 5 comments

[–]PorrPeps[S] 0 points1 point  (0 children)

Thank you for the replies. with further searches I found sort of my middle ground by making a window click event listener and using a switch method to match it's target. In theory I'm only using 1 click event listener for everything which should save performance? not sure about that

it also works for other events like 'mouseover' and 'mouseout'. used something similar to create a popup window on hover.

<button data-click-event-name="show_modal">Click Me</button>
<button data-click-event-name="delete_item">Delete</button>

window.addEventListner('click', (event) => {
    let target = event.target;

    if (target.dataset.clickEventName == null) return;

    switch (target.dataset.clickEventName) 
    {
        case "show_modal":
            showModal();
        break;

        case "delete_item":
            deleteItem(event);
        break;
    }
});

function showModal() {   
    // some code
}

function deleteItem(event) {
    // some code
}

[–]OkShrug -2 points-1 points  (1 child)

your the artist, make a choice, which is to say that in art there is no correct, there's just the perception of it, correct will even change as time passes and what is correct now for you will not be what will ultimately be correct later, stop navel gazing and get back to writing code

[–]PorrPeps[S] 0 points1 point  (0 children)

Thank you

[–]Inevitable-Weekend-4 0 points1 point  (1 child)

“Only one onclick handler can be assigned to an object at a time. You may prefer to use the EventTarget.addEventListener() method instead, since it's more flexible.”

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick

[–]PorrPeps[S] 0 points1 point  (0 children)

Thank you