I want to add custom context menu to my list element, but I have problem with detecting correct item. I have a list which contain many positions which represent each opened tab in browser.
<div class="position" data-id="0">
<div class="imgContainer"><img src="./favicons/trello.png"></div>
<div class="info">
<div class="title">Productivity | Trello</div>
<div class="address" title="https://trello.com/">
<span class="protocol">https://</span><span class="host">trello.com</span>
</div>
</div>
</div>
And I have also js code to capture right click on each position.
let position = document.querySelector(".position");
position.addEventListener("contextmenu", event => {
event.preventDefault();
event.stopPropagation();
});
For the test i have only one position. Problem is that event target doesn't contain my position as a target, but different children of that element. I log that event to the console, but no one property contain correct element.
contextmenu {
currentTarget: null,
explicitOriginalTarget: <div class="info">,
orginalTarget: <div class="info">,
srcElement: <div class="info">,
target: <div class="info"
}
Event listener has been added to position element, so I was expected that one of these properties will refer to correct position element, to extract data-id from it.
Is there simple way to get correct element as a target (position element, not any child of it)?