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

**URL:** https://forum.kirupa.com/t/a-addeventlistener-click-whichlinkwasclicked/645162
**Category:** web dev
**Created:** [December 3, 2020, 1:17am UTC](https://forum.kirupa.com/t/a-addeventlistener-click-whichlinkwasclicked/645162 "2020-12-03T01:17:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [December 3, 2020, 1:17am UTC](https://forum.kirupa.com/t/a-addeventlistener-click-whichlinkwasclicked/645162/1 "2020-12-03T01:17:11Z")

</div>

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

```auto
<!DOCTYPE html>
<html>
<body>

<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>

<script>
  a.addEventListener("click", WhichLinkWasClicked());

Function WhichLinkWasClicked(evt) {
// alert("Function WhichLinkWasClicked(evt)") ;
// alert(evt) ; 
		alert(evt.target.innerText);
		}
</script>

</body>
</html>

```

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [December 3, 2020, 2:50am UTC](https://forum.kirupa.com/t/a-addeventlistener-click-whichlinkwasclicked/645162/2 "2020-12-03T02:50:48Z")

</div>

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](https://www.kirupa.com/html5/finding_elements_dom_using_querySelector.htm), [Introduction to Events](https://www.kirupa.com/html5/javascript_events.htm), [Handling Events for Multiple Elements](https://www.kirupa.com/html5/handling_events_for_many_elements.htm).

😛

---

<div class="post-metadata">

### Author: ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)
#### Post date: [December 4, 2020, 12:33am UTC](https://forum.kirupa.com/t/a-addeventlistener-click-whichlinkwasclicked/645162/3 "2020-12-04T00:33:46Z")

</div>

Thanks Kirupa & for the links 🙂
