Lesson 10 of 10

Page magic

JavaScript can find a part of the page and change it.

Scene 1 of 5

A web page is made of parts. Look at this one!

A page with a heading "My page", words "I like cats." and a button "Click me".
Scene 1 of 5

Tip

Find a part first, then give it new words with textContent.

Library

All about page magic

A page has parts

A web page is made of parts. A heading, some words, a button.

Tags

Each part has a tag. h1 is a big heading. p holds words.

Finding a part

document.querySelector("h1") finds the heading. Keep it in a jar to use it.

Changing a part

textContent is the words inside a part. Give it new words, and the page changes!

A heading
<h1>My page</h1>
Find it
querySelector("h1")
New words
title.textContent = "Hi!"

Words to know

  • DOM = the page, in parts JavaScript can use
  • querySelector = finds a part of the page
  • textContent = the words inside a part