document.getElementById(e.target.id) and e.target effectively references the same DOM element when used in an event listener context where e is the event object passed to the event handler function. If the context is correct, the direct use of e.target should be preferred for simplicity and performance.
I think you may be referring to this code in the Scrim lesson document.getElementById(e.target.id).parentElement.classList.add('highlight')? Writing it as e.target.parentElement.classList.add('highlight') would still work I’m pretty sure.
Although the way I did it was longer, I felt it was a bit easier to read that way and felt more natural. Tbh, it’s very much matter of opinion though and fine to do it the second way. If I were going to use an element or the event more in that function I would definitely store it in a const for clarity.
Hope that helps! If I misunderstood your question, do get back to me!
Hi @Tom_Chant!
Thanks for replying.
Like your Essential JavaScript concepts lessons - well thought, interesting and with a lot of “muscle memory” training
Understood your explanation about clarity. Just was a bit confused - why searching for the element if we already have it in event object itself?
Agree with storing the element in const for clarity too, that make sense.
Actually, it can be even destructured from the event object with some other properties if needed (also within the callback event parameter):
someInputEl.addEventListener('change', ( { target } ) => {...
// or
const { name, target, value } = e
PS By the way, how you guys achieve “@some_name” when addressing to someone? I tried clicking on names and went to the profiles… Had to copy/pase then