-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassign5.js
67 lines (43 loc) · 1.38 KB
/
assign5.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//Traversing DOM
var itemList=document.querySelector('#items');
//parentNode
// itemList.parentNode.style.backgroundColor='#f4f4f4';
//parentElement
// itemList.parentElement.style.backgroundColor='#f4f4f4';
//childNodes
// console.log(itemList.childNodes);
//children
// console.log(itemList.children);
//firstChild
// console.log(itemList.firstChild);
//firstElemntChild
// console.log(itemList.firstElementChild);
//lastChild
// console.log(itemList.lastChild);
//lastElemntChild
// console.log(itemList.lastElementChild);
//createElement
var newDiv=document.createElement('div');
//Add class name
newDiv.className='Hello';
//create text node
var newText=document.createTextNode('Hello World');
//add text to div
newDiv.appendChild(newText);
var container=document.querySelector('header .container');
var h1=document.querySelector('header h1');
container.insertBefore(newDiv,h1);
//create Element
var newList=document.createElement('li');
//add class name
newList.className='list-group-item';
//add text to li
var newLiText=document.createTextNode('Hello World');
//add text to li
newList.appendChild(newLiText);
var newUl=document.getElementById('items');
newUl.prepend(newList);
// document.querySelector('ul').appendChild(newList);
// var newContainer=document.querySelector('div .list-group');
// var li=document.querySelector('ul li');
// newContainer.insertBefore(newList,li);