-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path44_innerHTMLouterHTML.html
More file actions
31 lines (24 loc) · 954 Bytes
/
Copy path44_innerHTMLouterHTML.html
File metadata and controls
31 lines (24 loc) · 954 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inner HTML Outer HTML</title>
</head>
<body><!--This is a comment-->
<span>Hey This is a span</span>
<span id="hide">This is a hidden</span>
</body>
</html>
<script>
console.dir(document.getElementsByTagName('span')[0])
// valid only for element nodes
console.log('1',document.body.innerHTML)
console.log('2',document.body.outerHTML) // outer HTML = inner HTML + self
// for all nodes
console.log('3',document.head.textContent) // (inside html - html tags) replaces tags by spaces
console.log('4',document.body.firstChild.nodeValue)
console.log('5',document.body.firstChild.data) // can be used to read comments
// hidden attribute
document.getElementById('hide').hidden = true
</script>