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