Escuchar click de botón created by parzibyte - https://repl.it/@parzibyte/Escuchar-click-de-boton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Escuchar click de botón</title> | |
<link href="style.css" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<button id="miBoton">Haz click sobre mí :)</button> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Obtener referencia a botón | |
// Recuerda: el numeral o # indica id | |
const boton = document.querySelector("#miBoton"); | |
// Agregar listener | |
boton.addEventListener("click", function(evento){ | |
// Aquí todo el código que se ejecuta cuando se da click al botón | |
alert("Le has dado click"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cuando usas la constante boton y addeventlistener abris un parentecis que nunca se cierra