Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Responding to User Events | Section
Core JavaScript for Web Development

bookResponding to User Events

メニューを表示するにはスワイプしてください

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.

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  26

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  26
some-alt