1

I'm trying to do something fairly simple where I need to listen for click events on the entire body of a page, and then get the element which is clicked and take an action based on that element.

Of course, the easy part is getting the clicked item, I just use

document.addEventListener('click', function(evt){
    console.log(evt.target);
})

The unfortunate thing is the evt.target in this context is returned as an html string, but when I output the evt object, I see a.click, which is what I need to pass into the document.querySelector.

What I would like to do is get either just the a.click as a string, or, even better, get the entire path from the body as a querySelector string, so for example body > header > d#container > span[some-attr="something] > a.click, if that is at all possible.

pedalpete
  • 21,076
  • 45
  • 128
  • 239

0 Answers0