Categories
JavaScript Answers

How to target an elements parent element using event.target with JavaScript?

Spread the love

To target an elements parent element using event.target with JavaScript, we use the parentNode property.

For instance, we write

const handleEvent = (e) => {
  const parent = e.currentTarget.parentNode;
};

to define the handleEvent function.

It it, we get the current element that triggered the event with e.currentTarget.

And we get its parent node with the parentNode property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *