Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active January 30, 2021 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/af5e77500f820425f21d362de8245274 to your computer and use it in GitHub Desktop.
Save parzibyte/af5e77500f820425f21d362de8245274 to your computer and use it in GitHub Desktop.
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