-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path47_nodeinsertion.html
More file actions
47 lines (39 loc) · 1.14 KB
/
Copy path47_nodeinsertion.html
File metadata and controls
47 lines (39 loc) · 1.14 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Node insertion</title>
<style>
.container{
border: 2px red solid;
}
</style>
</head>
<body>
<hr>
<div class="container">
<hr>
</div>
<hr>
</body>
</html>
<script>
let container = document.getElementsByClassName('container')[0]
// innerHTML
container.innerHTML = '<i> This is inserted by .innerHTML property </i>'
// good methods {can use for loop with these}
let div = document.createElement('div')
div.innerText = 'Hey this is created and inserted by js'
container.append(div)
container.prepend(div)
container.after(div)
container.before(div) // PROBLEM : only the last one will work
/*
1) node.append(div) -> adds at the end of node
2) node.prepend(div) -> insert at the starting of node
3) node.before(div) -> insert before node
4) node.after(div) -> insert after node
5) node.replaceWith(div) -> replaces node with given element
*/
</script>