-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomop.html
More file actions
48 lines (42 loc) · 1.29 KB
/
domop.html
File metadata and controls
48 lines (42 loc) · 1.29 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="container">
<p style="color:rgb(255, 0, 0)">First Paragraph</p>
</div>
<button id="appendBtn">Append</button>
<button id="prependBtn">Prepend</button>
<button id="replaceBtn">Replace</button>
<button id="removeBtn">Remove</button>
<script>
let container=document.getElementById('container');
// appended
document.getElementById("appendBtn").addEventListener('click',function(){
let newp=document.createElement("p");
newp.textContent="this is appended para";
container.appendChild(newp);
});
// prepend
document.getElementById("prependBtn").addEventListener('click',function(){
let newp=document.createElement("p");
newp.textContent="this is prepended para";
container.prepend(newp);
});
//replace
document.getElementById("replaceBtn").addEventListener("click", function() {
let newP = document.createElement("p");
newP.textContent = "Replaced the entire content!";
container.replaceChildren(newP);
});
//remove
document.getElementById("removeBtn").addEventListener("click", function() {
container.innerHTML = "";
});
</script>
</body>
</html>