mousedown event set on parent but keeps getting child element

Basically the title, when having the mousedown event on a parent I only want the target to be the parent wherever I click on the parent but Im getting the child as the target when clicking even though there's no event set on the child. Here's a jsbin to illustrate it: https://jsbin.com/bopoboqire/edit?html,css,js,output If anyone can help me understand why it's behaving like that pls
JS Bin
A live pastebin for HTML, CSS & JavaScript and a range of processors, including SCSS, CoffeeScript, Jade and more...
2 Replies
Chooβ™šπ•‚π•šπ•Ÿπ•˜
Use the event's currentTarget instead of the target. The fundamental difference is the currentTarget is the element that has the event listener attached to it. The target is the element that triggers the event handler, but it doesn't need to have the event listener attached to it directly. You could also use pointer-events:none in the CSS for the child, but it's cleaner to use currentTarget.
Axim
AximOPβ€’7mo ago
Ohhhh I see, I completely forgot about currentTarget !! I thought this property was only for some events but apparently its for all events that inherits the Event interface, right? Thx a lot for this I was wasting a lot of time for this
Want results from more Discord servers?
Add your server