Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
How to call a function in JS without calling the function of Parent element

How can I make the button disappear work in the example below

<!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>

When I click on button disappear I want to call only its function - which is child(). not the parent() function which is when I click the div

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda