+ 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.
+ 3
You can check if the event target has a certain id:
event.target.id == ...
https://sololearn.com/compiler-playground/WtV7jl8Exh21/?ref=app
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.



