Chapter 1 deck Chapter 2 deck Chapter 3 deck Chapter 4 deck Chapter 5 deck Chapter 6 deck Chapter 7 deck Chapter 8 deck Chapter 9 deck Chapter 10 deck Chapter 11 deck Chapter 12 deck Chapter 13 deck Chapter 14 deck

What JavaScript Can Do

4 slides · use ←/→ or Space to navigate, F for fullscreen.

Reading view

← Back to the full Chapter 5 deck

What JavaScript Can Do
Fullscreen for presentation · Print / PDF for a handout
1 / 4
Lesson

What JavaScript Can Do

Core capabilities and the three patterns of DOM manipulation.

What JavaScript Can Do

Core Capabilities

CapabilityDetail
HTML designer toolGives HTML designers a full programming capability to build logic directly into web pages.
Dynamic textWrites variable content into HTML: "Hello " + name.
Event reactionsExecutes code when events happen — for example when a user clicks an element.
Client-side validationValidates form data before submission, saving unnecessary server round-trips.
DOM manipulationAccesses and modifies the Document Object Model — a tree representation of the page.
User notificationsShows information or alerts without interrupting workflow (alert, confirm, prompt).
Back-end data loadingMakes HTTP requests (AJAX / Fetch API) to retrieve or send data without reloading.
Interactive presentationsLibraries like Reveal.js and Impress.js build interactive slide decks entirely in JavaScript.

JavaScript reacts to events triggered by the user or browser — this makes pages feel alive and responsive without a server round-trip.

What JavaScript Can Do

Changing HTML with JavaScript

// 1. Change HTML content
document.getElementById("demo").innerHTML = "Hello JavaScript!";

// 2. Change an HTML attribute
var image = document.getElementById("myImage");
if (image.src.match("bulbon")) {
  image.src = "pic_bulboff.gif";
} else {
  image.src = "pic_bulbon.gif";
}

// 3. Change HTML styles (CSS)
document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "blue";

These three patterns — innerHTML, attribute changes and style changes — are the foundation of all DOM manipulation in JavaScript.

What JavaScript Can Do

Activity — complete the code

Complete the three DOM manipulation patterns.

// 1. Change HTML content
document.getElementById("demo"). = "Hello JavaScript!";
 
// 2. Change an HTML attribute
var image = document.getElementById("myImage");
image. = "pic_bulbon.gif";
 
// 3. Change HTML styles
document.getElementById("demo").style. = "25px";