forked from iamshaunjp/JavaScript-DOM-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (38 loc) · 1.47 KB
/
app.js
File metadata and controls
55 lines (38 loc) · 1.47 KB
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
/*
//this is how to grab html element by id
var banner = document.getElementById('page-banner');
var bookList = document.getElementById('book-list');
//grab element by class
var titles = document.getElementsByClassName('title');
titles[0]; //h1
//checek if titles is an array
console.log(Array.isArray(titles)); //it says false bc "titles" is not an array
console.log(Array.isArray(Array.from(titles))); //this converts "titles" to an array
//get each elelement in this array
Array.from(titles).forEach ((item) =>{
console.log(item);
})
//by tagname
var li = document.getElementsByTagName('li')
//it does the same thing as getElementById
//get wise man's fear
var wmf = document.querySelector('#book-list li:nth-child(2) .name');
console.log(wmf);
//return all elements in the collection
var books = document.querySelectorAll('#book-list li .name');
//console.log(books);
books.forEach(function(book){
//modify the text content in the book list
book.textContent += '(book title)';
});
//modify the content inside book list
var bookList = document.querySelector('#book-list');
bookList.innerHTML = '<h2> Books and more books... </h2>';
bookList.innerHTML += '<p>this is how you add HTML</p>'
*/
var banner = document.querySelector('#page-banner');
console.log('#page-banner node type is:', banner.nodeType);
console.log('#page-banner node name is:',banner.nodeName);
console.log('#page-banner has child nodes:',banner.hasChildNodes());
//clone node
var clonedBanner = banner