-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05app.js
More file actions
71 lines (55 loc) · 1.54 KB
/
05app.js
File metadata and controls
71 lines (55 loc) · 1.54 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let val;
const list = document.querySelector("ul.collection");
const listItem = document.querySelector("li.collection-item:first-child");
val = list;
val = listItem;
// HTML collection
val = list.children;
// get childNodes
val = list.childNodes;
val = list.childNodes[0];
val = list.childNodes[0].nodeType;
/*Node type
1:Element
2:attribute
3:text node
8:Comment
9:Documnet itself
10:Doctype
*/
// get children element nodes
val = list.children[2];
list.children[1].textContent = "Hello";
// Children of Children
val = list.children[3].children;
// We can also add id to the children of children
list.children[3].children[0].id = "new-id";
val = list.children[3].children[0];
// list.children.id = "id"; yesari id rakhna pani milcha
val = list.children;
// euta child lina pani milcha but it gives #text which is nodelist
val = list.firstChild;
// so use this to get HTML element
val = list.firstElementChild;
// Last child
val = list.lastChild;
list.lastElementChild.id = "put";
val = list.lastElementChild;
// Parent node
val = list.parentNode;
val = list.parentElement;
// they both usually gives same o/p
// Parent of parent
val = list.parentElement.parentElement;
// get next sibling
val = listItem.nextSibling;
// this gives #text so do this
val = listItem.nextElementSibling;
// another sibling
val = list.nextElementSibling.nextElementSibling;
val = listItem.nextElementSibling.nextElementSibling;
// Previous sibling
val = listItem.previousElementSibling;
val = list.previousElementSibling;
// We can also go through previous of previous
console.log(val);