cd ../labs
JavaScriptintermediateabout 40 minutes
Making pages interactive
Find elements, react to clicks and typing, and build a working counter and to-do list.
By the end you can
- Find elements and change what they show
- Run code when someone clicks or types
- Add and remove elements from a page
- Keep what is on screen in step with your data
Easier if you did first
0 of 3 done
step 1 of 3
Find an element and change it
document.querySelector takes a CSS selector and gives you the first matching element.
Once you have it, textContent reads or replaces the text inside it.
Set the text of #greeting to anything containing the word Ghana.
const title = document.querySelector("h1");
title.textContent = "New heading";What we check
- #greeting mentions Ghana
- You looked the element up in JavaScript
- You used textContent rather than innerHTML
index.htmlhtml
script.jsjavascript
preview