I am getting some issues while trying to get the data attribute of any html element.
The problem is i am getting the data attribute in 30% of the cases. The rest is returning undefined.
Here's what i want to trigger:
document.addEventListener(DOMContentLoaded,() => {
document.body.addEventListener(click,(e) => {
console.log(clicked);
console.log(e.target.dataset.link + is the link clicked) // this is returning undefined most of the times.
if (e.target.dataset.link !== undefined) {
console.log(got the link)
navigateTo(e.target.dataset.link);
}
})
// router();
})
<div class=cell data-link=/dashboard/posts tabindex=1>
<i class=material-icons>assignment</i>
<span>Posts</span>
</div>
How is this even possible ?
And how can i prevent this ?
I can't remove the onclick event listener for the body.