Contenu du cours
Module 1 — Discovering JavaScript
What JavaScript does, where to write your code, the console and a first script.
0/4
Module 2 — Language fundamentals
Variables and types, operators and conditions, then loops.
0/4
Module 3 — Functions and interactivity
Writing functions, responding to events and manipulating the DOM.
0/4
Module 4 — Going further
Arrays and objects, an introduction to APIs with fetch, and best practice.
0/4
JavaScript for beginners

Interactivity is built on events: user actions (a click, a hover, a key press) that your code can respond to.

Some common events

  • click — the user clicks an element.
  • mouseover — the mouse hovers over an element.
  • keydown — a key is pressed on the keyboard.

Listening for an event

You attach a response to an element with addEventListener:

const bouton = document.querySelector("button");
bouton.addEventListener("click", function() {
  alert("You clicked!");
});

The idea is simple: « when this event happens on this element, run this function« . The function you supply is known as a callback.

Key takeaway: addEventListener lets you respond to user actions. It is the heart of an interactive page.

Prix indicatifs, convertis depuis l'euro