3 buttons in a single div with no gap or marginI have a parent div that acts as a container for three full-width, adjacent buttons (with no gaps in the HTML structure). I've added a single click event listener to the parent div to handle clicks on any of the buttons using event delegation.
However, when a user clicks precisely on the visual gap or border between the buttons, the click event still registers on the parent div, but the event.target is the div itself, not a button. This leads to my code trying to process an "undefined" button choice.
Is there a more elegant or robust solution, perhaps using a different event, a CSS technique, or a different JavaScript pattern altogether? The "ignore" method works (ignoring the event with if condition), but I'm curious if there's a way to architect this so the gaps simply aren't clickable, or if there's a best practice I'm missing for this common UI pattern.
pointer-events: noneon the container div,pointer-events: autoon the buttons.