a.addEventListener("click", WhichLinkWasClicked());

Sorry , stumped again:
Uncaught SyntaxError: Unexpected identifier
“Function WhichLinkWasClicked(evt) {”

<!DOCTYPE html>

<p>This example uses the addEventListener() method to catch which kink was clicked.</p>

<a href="https://www.google.com">Visit google.com!</a>
<a href="https://www.duckduckgo.com">Visit duckduckgo.com</a>

  a.addEventListener("click", WhichLinkWasClicked());

Function WhichLinkWasClicked(evt) {
//        alert("Function WhichLinkWasClicked(evt)") ;
//	    alert(evt) ; 


You should lowercase the Function to function. You also don’t need the open/closing parenthesis as part of WhichLinkWasClicked in the event listener. This will work:

a.addEventListener("click", WhichLinkWasClicked);

Lastly, you are calling addEventListener on a, but a isn’t actually defined in your code. You need to reference it via querySelector or querySelectorAll. For what you are trying to do, where you have two elements, it is slightly more involved. I encourage you to read the following three articles to get a better idea of how to make this work: Finding Elements in the DOM, Introduction to Events, Handling Events for Multiple Elements.


Thanks Kirupa & for the links :slight_smile:

1 Like