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

92
Vistas
JavaScript onClick on embedded elements

I have the following JavaScript:

<div>
    <tr onClick="click1()">
        <td>
            click 1
        </td>
        <td onClick="click2()">
            click 2
        </td>
    </tr>
</div>

function click1() {
  alert(1);
}

function click2() {
  alert(2);
}
<table border="1">
  <tr onClick="click1()">
    <td>
      click 1
    </td>
    <td onClick="click2()">
      click 2
    </td>
  </tr>
</table>

If I click 'click 1', the click1() function is called as expected. If I click 'click 2', the click1() & click2() functions are both called.

Question

How do I make the click on 'click 2' only call the click2() function, and not call the click1() function?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Well, the easiest way is just to move your 'click 1' trigger to the button itself:

<div>
    <tr>
        <td onClick="click1()">
            click 1
        </td>
        <td onClick="click2();">
            click 2
        </td>
    </tr>
</div>

However, I'm assuming you want to keep the click 1 trigger where it is, in which case you can add event.stopPropagation() to the event:

<div>
   <tr onClick="click1();">
       <td>
           click 1
       </td>
       <td onClick="click2(); event.stopPropagation();">
           click 2
       </td>
   </tr>
</div>
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