My Favorite JavaScript Method - Element closest() in 2 Minutes

preview_player
Показать описание
Yes, I have a favorite method 🫡

The Element "closest" method in the JavaScript DOM allows you to begin at a child element and traverse up the DOM using a selector to find a matching parent. Perfect for event listeners.

For your reference, check this out:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

I used to use closest method in jquery back in the old old olllld days. Happy to see it natively in js.

MinaLuke
Автор

❤❤ omg i dont know about this method of dom i always find ways to react on the parent element but man this way is so easier than any other trick

ashishkumar-jocj
Автор

Add the event listener to the document and check the event data to determine which element triggered the click...TBH I don't see the use cases...

montebont
Автор

I used closest so much I thought I was doing something wrong 😂

tochimclaren
Автор

I liked your vs code theme, what is it?

atikurrehman
Автор

Did not know this one...🙏🙏🙏🙏🙏👌👌👌👌👌👏👏👏👏🌹🌹🌹🖖🖖🖖🖖🖖🖖

suelingsusu