forked from rocketacademy/basics-next-steps-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (19 loc) · 703 Bytes
/
script.js
File metadata and controls
21 lines (19 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// console.log('yay!');
// make the variables out (from html id) of the input & button
var input = document.querySelector("#starter-ex");
var button = document.querySelector("#starter-button");
// call this function
var myButtonClicked = function () {
// assign value typed from input to the variable
var typedValue = input.value;
// create a new h2 element
var newHTwo = document.createElement("h2");
// set text inside newHTwo element
newHTwo.innerText = typedValue;
// make newHTwo appear on screen
document.body.appendChild(newHTwo);
// Empty the HTML input box
input.value = "";
};
// Activate the function when user *click*
button.addEventListener("click", myButtonClicked);