I have an event listener for an object and when I click the object it’s fine, but when I click the child, event.target returns the child. Is there a way to make it so that it only returns the object I assigned the event listener to?
This is what I have as of now:
function myFunction(event) {
if (event.target == something) {
console.log('test') // expected test every time I click the object something in the html
}
}
something.addEventListener('click', myFunction)
somethingelse.addEventListener('click', myFunction)
It only logs ‘test’ in the console when I click the margin/padding outside of the child because technically the event.target is not ‘something’ and rather the child of something.
Is there any way to access the object I am adding the event listener to (something) rather than the item being clicked?
Thanks.