+ 5
Danielle Lee Welcome to sololearn Just use this: if (event.target === myElement) Basically, you're telling JS, “Hey, only react if myElement was actually clicked.” Since you're using event delegation on body, this helps you catch clicks but still keep it specific. Simple and clean.
17th Apr 2025, 11:26 AM
IИVƗS!BŁΞ (Offline)
IИVƗS!BŁΞ (Offline) - avatar
+ 3
You can check if the event target has a certain id: event.target.id == ... https://sololearn.com/compiler-playground/WtV7jl8Exh21/?ref=app
17th Apr 2025, 11:26 AM
Lisa
Lisa - avatar
0
Lisa Yes, but only if the element has an ID, though if it doesn't it's still possible to use any of className, classList, name, etc, which are unique enough.
19th Apr 2025, 5:27 AM
Tom Shaver
Tom Shaver - avatar