Can you target an elements parent element using event.target?
To use the parent of an element use parentElement
:
function selectedProduct(event){
var target = event.target;
var parent = target.parentElement;//parent of "target"
}
I think what you need is to use the event.currentTarget
. This will contain the element that actually has the event listener. So if the whole <section>
has the eventlistener event.target
will be the clicked element, the <section>
will be in event.currentTarget
.
Otherwise parentNode
might be what you're looking for.
link to currentTarget
link to parentNode
handleEvent(e) {
const parent = e.currentTarget.parentNode;
}