0

I am having trouble getting the parent node of a br element which triggered a ClipboardEvent.

What I am trying to achieve is to recursively match its parent to a certain class, but the br element's parentNode property is null:

br element

Here is the DOM tree:

br element in DOM tree

The path property of the ClipboardEvent seems to capture the hierarchy but it is not standard: Event path

Update:

I figured out why this is happening.

The br element was replaced by some new element upon pasting by the first event handler, and in my 2nd event handler(this one that I am having issue with), br is no longer in DOM tree.

Community
  • 1
  • 1
paradite
  • 5,918
  • 3
  • 37
  • 57

1 Answers1

1

Try e.target.parentElement

e.target will get the target of the event, in this case the <br>

Demo: https://codecanister.com/Project/d547eed9/6/result/

jlynch630
  • 687
  • 8
  • 15