Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda