Live coding: The Document Object Model
Changing the DOM with JavaScript
html
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sandbox: Changing the DOM with JavaScript</title>
<link rel="stylesheet" href="styles.css">
<script src="app.js" defer></script>
</head>
<body>
<main class="container">
<h1>
<a href="index.html">
Sandbox: Changing the DOM with JavaScript
</a>
</h1>
<section class="flex-container">
</section>
</main>
</body>
</html>
js
const songs = [
"Do They Know It's Christmas?",
"Relax",
"I Just Called to Say I Love You",
"Two Tribes",
"Don't You Want Me",
]
let flexContainer = document.querySelector('.flex-container')
for (let song of songs) {
flexContainer.innerHTML += `<p>${song}</p>`
}
let h1 = document.querySelector('h1')
h1.textContent = h1.textContent + '!'
Creating a webpage from scratch from a data file
html
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Creating a webpage from data with JS</title>
<link rel="stylesheet" href="index.css" />
<script defer type="module" src="app.js"></script>
</head>
<body>
<h1 style="place-self: center">Creating a webpage from data with JS</h1>
<p style="place-self: center">
Open the browser console to see the program outputs.
</p>
</body>
</html>
js
export const data = [];
js
import { data } from './data.js';
console.log(data);