-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path01-examining-the-document-object.js
67 lines (56 loc) · 1.37 KB
/
01-examining-the-document-object.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
/**
* ******************************
* DOM Object Properties
* ******************************
**/
/**
* ********************
* DOM PROPERTIES
* ********************
**/
let val;
val = document;
val = document.all;
val = document.all[2];
val = document.all.length;
val = document.head;
val = document.body;
val = document.doctype;
val = document.domain;
val = document.URL;
val = document.characterSet;
val = document.contentType;
/**
* ********************
* SELECTING DOM PROPERTIES WITHOUT SELECTORS
* ********************
**/
val = document.forms;
val = document.forms[0];
val = document.forms[0].id;
val = document.forms[0].method;
val = document.forms[0].action;
val = document.links;
val = document.links[0];
val = document.links[0].id;
val = document.links[0].className;
val = document.links[0].classList[0];
val = document.images;
val = document.scripts;
val = document.scripts[2].getAttribute('src');
/**
* ********************
* CONVERT HTML COLLECTION TO ARRAYS
* ********************
**/
let scripts = document.scripts;
let scriptsArr = Array.from(scripts); // Converts HTML collection into an Array Object
// Without array conversion this will get a TypeError message
scriptsArr.forEach(function(script) {
console.log(script);
});
// Log only the src links.
scriptsArr.forEach(function(script) {
console.log(script.getAttribute('src'));
});
console.log(val);