I have an asp.net app, on the app’s dashboard the names of websites are pulled through to the view from a SQL DB like this.
<h1>My Websites</h1>
@{
foreach (var website in Model.websites)
{
<table>
<tr>
<td> <a id="websiteLink" href="">@website </a> </td>
</tr>
</table>
}
}
which works fine:
I am trying to have a click event for each of the website links, in order to pull info based on the clicked website.
<script>
var website_link = document.getElementById("websiteLink");
website_link.addEventListener("click", function () {
//test the click event
alert("link clicked");
})
</script>
But the click event only works on the first link? when I inspect the page at runtime with chrome devs tools, the correct ID is added to the second link but the click event does not fire? Please help me.
My goal is to render information based on the clicked link, I basically just need the html.value of the clicked link to complete my task…
Thank you in advance for any suggestions!