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

159
Vistas
Cómo llamar a una función en JS sin llamar a la función del elemento principal

¿Cómo puedo hacer que el botón desaparezca funcione en el siguiente ejemplo?

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>title</title> </head> <body> <div id="div1" style="height: 100px; background-color: red;" onclick="parent()"> <button onclick="child()">disapear</button> </div> <script> function parent(elem) { document.getElementById("div1").style.display = "block"; } function child(elem) { document.getElementById("div1").style.display = "none"; } </script> </body> </html>

Cuando hago clic en el botón desaparecer, quiero llamar solo a su función, que es child() . no la función parent() que es cuando hago clic en el div

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>title</title> </head> <body> <div id="div1" style="height: 100px; background-color: red;" onclick="parent(event)"> <button onclick="child(event)">disapear</button> </div> <script> function parent(elem) { document.getElementById("div1").style.display = "block"; } function child(elem) { elem.stopPropagation(); document.getElementById("div1").style.display = "none"; } </script> </body> </html>
about 4 years ago · Santiago Trujillo 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