-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom_deletenode.html
More file actions
41 lines (35 loc) · 968 Bytes
/
Copy pathdom_deletenode.html
File metadata and controls
41 lines (35 loc) · 968 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
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
<head>
<script>
function delete1() {
var the_node = document.getElementById("firstP");
the_node.parentNode.removeChild(the_node);
}
function delete2() {
var the_node = document.getElementsByTagName("p")[0];
the_node.parentNode.removeChild(the_node);
}
function delete3() {
var the_parent = document.getElementById("theBody");
the_parent.removeChild(the_parent.firstChild);
}
</script>
</head>
<body id="theBody">
<p id="firstP">
Hello.
</p>
How are you?
<br>
<p id="secondP">
It's a nice day!
</p>
<button type="button" onclick="delete1()">Example 1</button>
<button type="button" onclick="delete2()">Example 2</button>
<button type="button" onmousedown="delete3()">Example 3</button>
<p>
Reload the page to reset the DOM.
</p>
</body>
</html>