Teyro
CoursesFor creatorsBlog
Log inGet started
Tey Mascot
LOADING.

Every expert you admire was once a beginner who refused to quit.

Teyro

The fun way to finish learning coding and AI: short daily lessons with streaks, leagues and friends.

Get the app

Learn

  • All courses
  • Learn coding
  • Learn AI
  • Learn online
  • How it works
  • Leagues
  • Get the app

Creators

  • Teach on Teyro
  • How teaching works
  • Teach coding online
  • Teach AI online
  • Join as a Founding Creator
  • Creator log in

Resources

  • Blog
  • Features
  • Use cases
  • Compare
  • FAQ

Legal

  • Terms of Use
  • Privacy Policy

© 2026 Teyro · support@teyro.app

HomeBlogSkill Building & Careers
Skill Building & Careers

JavaScript DOM Tutorial for Beginners: Change Pages, Handle Events

A beginner JavaScript DOM tutorial: what the DOM is, selecting and changing elements, events like clicks and typing, building lists, with working examples.

The Teyro TeamOct 25, 20262 min read
On this page9 sections
  1. Direct answer
  2. Selecting and changing
  3. Common events
  4. Building a list from data
  5. textContent vs innerHTML
  6. Next steps
  7. Where Teyro fits
  8. The bottom line
  9. More coding guides

HTML and CSS make a page. JavaScript makes it respond. The DOM is how JavaScript talks to the page.

Direct answer

The DOM (Document Object Model) is the browser's live version of your page. With JavaScript you select elements, change their text and styles, and listen for events such as clicks and typing. The core tools are querySelector, textContent, classList and addEventListener.

Selecting and changing

<h1 id="title">Hello</h1>
<button id="btn">Change</button>
const title = document.querySelector('#title');
const btn = document.querySelector('#btn');

btn.addEventListener('click', () => {
  title.textContent = 'Hello, Sam';
  title.classList.add('highlight');
});

When the button is clicked, the heading text changes and gets a CSS class.

Common events

EventWhen it fires
clickAn element is clicked or tapped
inputThe value of an input changes as you type
submitA form is submitted
keydownA key is pressed
DOMContentLoadedThe page has loaded

Building a list from data

const fruits = ['apple', 'banana', 'cherry'];
const list = document.querySelector('#list');

fruits.forEach((fruit) => {
  const li = document.createElement('li');
  li.textContent = fruit;
  list.appendChild(li);
});

textContent vs innerHTML

Use textContent for text. innerHTML interprets HTML, which can be unsafe if the text comes from users.

Next steps

Check input in forms: JavaScript form validation example. New to the language? Read JavaScript for beginners.

Where Teyro fits

Teyro's Interactive Web Pages with JavaScript makes web pages come alive: change what's on the page, react to taps and typing, build lists from data and check forms, on a live page in every lesson. It has 37 lessons and is free to start.

The bottom line

Select, change, listen. Repeat.

More coding guides

  • JavaScript form validation example
  • JavaScript for beginners
  • HTML tutorial for beginners
  • Interactive JavaScript course

Frequently asked questions

What is the DOM?

The Document Object Model: the browser's live representation of a web page as objects that JavaScript can read and change.

How do I change text on a page with JavaScript?

Select the element with document.querySelector, then set its textContent.

What are JavaScript events?

Things that happen on a page, such as clicks, key presses, form submissions and page loads. You listen for them with addEventListener.

Should I use innerHTML or textContent?

Use textContent for plain text. innerHTML parses HTML and can be unsafe with user-provided text.

Make pages come alive on a live page

Interactive Web Pages with JavaScript teaches you to change the page, react to taps and typing, build lists and check forms. 37 short lessons, free to start.

See the Interactive JavaScript course

Free to start · No credit card needed

Share

Written by

The Teyro Team

Learning Team at Teyro

We build Teyro — an AI-powered learning platform that turns skill-building into a daily habit through bite-sized, gamified lessons. We write about the learning science and study strategies that shape our product.

More from The Teyro Team

On this page

  • Direct answer
  • Selecting and changing
  • Common events
  • Building a list from data
  • textContent vs innerHTML
  • Next steps
  • Where Teyro fits
  • The bottom line
  • More coding guides

Keep reading

Skill Building & Careers

Best Careers for 2027: High-Demand Jobs and the Skills to Get Them

The best careers for 2027 and the jobs most in demand, based on BLS and World Economic Forum data, plus the skills each path needs.

Oct 30, 20263 min read
Skill Building & Careers

Best Certifications for 2027: Tech, Data, Cloud and Business

The best certifications for 2027 in cloud, security, data, project management and AI, who each one suits, and when a portfolio matters more.

Oct 30, 20263 min read
Skill Building & Careers

Best Programming Language to Learn in 2027 (for Your Goal)

The best programming language to learn in 2027 depends on what you want to build. Compare Python, JavaScript, TypeScript, SQL and C.

Oct 30, 20263 min read