forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom_manipulation_html.js
More file actions
49 lines (45 loc) · 1.36 KB
/
Copy pathdom_manipulation_html.js
File metadata and controls
49 lines (45 loc) · 1.36 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
// Top most tree nodes
const html = document.documentElement; // The topmost document node.
const body = document.body; // To access body of the page. It can be null. That means it doen't exist.
const head = document.head; // To access head tag of the page.
// DOM navigation
const parentNode = document.parentNode;
const firstChild = document.firstChild;
const lastChild = document.lastChild;
const nextSibling = document.nextSibling;
const previousSibling = document.previousSibling;
// Element-only navigation
const parentElement = document.parentElement;
const firstElementChild = document.firstElementChild;
const lastElementChild = document.lastElementChild;
const nextElementSibling = document.nextElementSibling;
const previousElementSibling = document.previousElementSibling;
// DOM collections
const childNode = document.body.childNodes;
const tableBodies = table.tBodies;
const tableRows = table.rows;
const trCollection = tbody.rows;
const trCells = tr.cells;
/*
Example html template
<html>
<head>...</head>
<body>
<table id="table">
<tr>
<td>one</td>
<td>two</td>
</tr>
<tr>
<td>three</td>
<td>four</td>
</tr>
</table>
</body>
<script>
// Extract "two"
let tableRows = table.rows;
let trCells = tableRows[0].cells[1];
</script>
</html>
*/