Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active January 30, 2021 15:16
Embed
What would you like to do?
Escuchar click de botón created by parzibyte - https://repl.it/@parzibyte/Escuchar-click-de-boton
<!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>
// 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");
});
@parzibyte
Copy link
Author

Hola @zacarias-angel, el paréntesis abierto en la línea 5 de script.js se cierra en la línea 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment