Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="es">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
- <title>Ejemplo de Contador con Botones</title>
- </head>
- <body>
- <div class="container py-5 text-center bg-warning">
- <button class="btn btn-info">Aumentar</button>
- <button class="btn btn-danger">Disminuir</button>
- <h4 class="mt-5">Contador: <span id="resultado">0</span></h4>
- </div>
- <script>
- var botonAgregar = document.querySelector(".btn-info");
- var botonDisminuir = document.querySelector(".btn-danger")
- var resultado = document.querySelector("#resultado");
- var contador = 0;
- botonAgregar.addEventListener("click", function()
- {
- console.log("Se hizo click");
- contador++;
- resultado.textContent = contador;
- });
- botonDisminuir.addEventListener("click", function()
- {
- console.log("Se hizo click en disminuir");
- contador--;
- resultado.textContent = contador;
- })
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement