<< Back

Exercise 1.1 - Buttons and Inputs

h) Change the header

This is the console. All output created with writeLog() is shown here.

Type a text into the input field and press 'Set header'.


script.js

This is the JavaScript code behind the above application.

/* global writeLog, getInput */
writeLog("Solution for exercise 1.1 h)");
function setHeader() {
// Get the text for the header from the input field
var text = getInput("headerText");
// Set the h1's text
document.querySelector("h1").textContent = text;
// Clear the input field
document.getElementById("headerText").value = "";
}