Prevent click from bubbling to parent

Hi, I have the following structure:
<div>
Categories
<a href="/">x</a>
</div>
<div>
Categories
<a href="/">x</a>
</div>
Where the button div has an event listener so that it will display a drop-down menu. The anchor tag in this case will redirect to the main page which effectively will remove the category filter that is selected. The problem is clicking on the link triggers the click event on the parent and for a split second the drop-down menu is visible. Is there a way to prevent the click event from bubbling to the parent without using JavaScript? I'm looking for something that is pretty much the opposite of pointer-events: none, causing clicks to never go through this element. Thanks!
10 Replies
b1mind
b1mind•2y ago
Ummm this seems wrong Rethink your life and don't put a href in a button please
Joao
Joao•2y ago
Done, now it's a div same question? 😅
13eck
13eck•2y ago
Is there a way to prevent the click event from bubbling to the parent without using JavaScript?
No, there's not.
Joao
Joao•2y ago
All right thanks!
MarkBoots
MarkBoots•2y ago
there might be nice and clean solutions, but hard to tell without knowing the rest of your app
Joao
Joao•2y ago
It's all right its just a quick protoype and wnated to take a shortcut
13eck
13eck•2y ago
If you explain a bit more about what you're trying to do we might be able to find a different tool for this specific job
Joao
Joao•2y ago
It's a dropdown menu where user selects a category to filter some posts. When a category is selected already, it displays a little cross to remove any filters and display everything again. Currently the filtering is done using query parameters, so I thought of using a link to reset them by 'redirecting' to main page since it happens to look the same but without filters. But like I said I was looking for a shortcut to avoid having to do all of this in JavaScript, its just for a quick demo. Thank you though
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Joao
Joao•2y ago
Yes, it seems there's no other way
Want results from more Discord servers?
Add your server