-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek5.js
27 lines (25 loc) · 829 Bytes
/
week5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// createElement, appendChild, insertBefore
function buttoncreate (){
var parent = document.getElementById('parent');
//var display = document.getElementById('display');
var newdiv = document.createElement('div');
var txt = document.createTextNode('Cookie');
newdiv.appendChild(txt);
parent.insertBefore(newdiv, null);
}
//remove child
function buttonremove() {
console.log("removed something");
var removeclick = document.getElementById("removeclick");
var buttonclick = document.getElementById("buttonclick");
var parent = document.getElementById("parent");
if (parent.childNodes.length > 0){
parent.removeChild(parent.childNodes[0]);
}
else if (buttonclick) {
buttonclick.parentNode.removeChild(buttonclick);
}
else {
removeclick.parentNode.removeChild(removeclick);
}
}