Event listeners in JSX

why is there an e passed in the function, what does it do, and why won’t the image change if instead of having the link of the image i put {dog} where dog is a variable holding the link to the dog’s image?

event listeners in JSX - Codecademy

The e is an argument that, when the function is called, is passed in as the event (as in, the user clicking the button). You can use this to trace what element the event occurred on, and then find/set its value. As for the second half of your question, can you elaborate, please?

oh so basically e is what the function is waiting to see if it changes and if it does then specifically the src of e will be changed, correct?

also, for the second half i meant this :point_down: where i made a variable called dog and its value is the img to the dog pic it changes to

1 Like

Pretty much, yeah…


As for your second question, you should be able to, but you don’t need to wrap the variable name in curly braces, since your function declaration (and all the code in it) isn’t within an HTML/JSX component…