0

I am creating a chrome extension by which i will be able to get xpath of the element on which it is clicked. event.currentTarget gives me document and event.toElement gives me whole body tag. chrome is giving me whole document or body puzzled by this behaviour, am i missing something?

or what are other ways to do that? please help.

enter image description here

ThinkTank
  • 1,737
  • 5
  • 22
  • 36
  • `toElement` is an ancient IE-compatible alias for `relatedTarget` so you don't need it. As for the difference between currentTarget and relatedTarget, there are existing answers (like [this one](https://stackoverflow.com/a/31866151)). – wOxxOm Jul 04 '19 at 15:17
  • thanks for that info but how i will get exactly on which element it is clicked on it it is showing document as currentTarget because i have added event Listener on whole document. – ThinkTank Jul 05 '19 at 06:52
  • Simply use `event.target`, there's no need for currentTarget or relatedTarget at all AFAICT. – wOxxOm Jul 05 '19 at 08:16
  • https://stackoverflow.com/questions/8813051/determine-which-element-the-mouse-pointer-is-on-top-of-in-javascript – ThinkTank Jul 10 '19 at 10:41
  • got answer from my x y co ordinate and got element – ThinkTank Jul 10 '19 at 10:42

0 Answers0