A button on a web page changing a message A simple browser window shows the words Hello, Maple Trail, and a blue button labeled Change it. Hello, Maple Trail Change it Hello!

Next Steps · Lesson 1 of 4

A little bit of JavaScript

HTML names the parts of a page. CSS gives them a look. JavaScript is the part that can make something happen when you press a button.

Big idea

A little script can change the words on a page, show a picture, or hide one. The page is still the same file. JavaScript just tells the browser what to do when something happens, like a click.

What a tiny script can do

  • Listen for a click on a button.
  • Change the words in a heading or a sentence.
  • Show or hide a picture.

Here is the idea, written in the same language a browser reads. You do not have to memorize it. A grown-up can help you read it aloud.

button.addEventListener("click", function () {
  message.textContent = "Hello, Maple Trail!";
});

This lesson only uses buttons we already wrote. You cannot type your own code here, and nothing is sent or saved.

Make the page do something

Tap each button and watch the pretend Maple Trail page change. This is only practice. Nothing is saved or sent.

Welcome to Maple Trail.

Try both buttons

Tap a button to see JavaScript change the page.

Quick check

1. JavaScript is mainly for…

2. If a button changes a greeting, what stayed the same?

3. Who should help if you want to write a tiny script of your own?

Talk about it with a grown-up

  • Can we find a button on a favorite page and guess what it does before we press it?
  • If we added one button to our tiny Maple Trail page, what would we want it to change?
  • Why is it safer to try a short script together, instead of pasting code from a stranger?