Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
How to have click events for iterated links

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:

pic of websites pulled from db

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!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

My solution :

document.querySelectorAll('.websiteLink').forEach(item => {
  item.addEventListener('click', event => {
    alert(item.innerHTML);
  });
});

From here, How would I be able to access this item.innerHTML value in my controller or model ?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!