Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Responding to User Events | Section
Fundamentos de JavaScript

bookResponding to User Events

Desliza para mostrar el menú

Web pages become interactive when JavaScript responds to user actions like clicks or typing.

To handle user actions, use the addEventListener() method.

const button = document.querySelector(".btn");

button.addEventListener("click", () => {
  console.log("Button clicked");
});

When the button is clicked, the function runs.

Common events:

  • "click": when an element is clicked;
  • "input": when a user types in a field;
  • "submit": when a form is submitted.

Example with user input:

const input = document.querySelector("input");

input.addEventListener("input", () => {
  console.log(input.value);
});

JavaScript listens for events and runs code in response, which makes web pages interactive.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 26

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 1. Capítulo 26
some-alt