-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
46 lines (38 loc) · 1.16 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript DOM</title>
<style>
.container{
color: blue;
}
.js{
border: 2px solid black;
}
</style>
</head>
<body>
<div id="container" style="display: block; height: 200px; width: 300px; margin: 10px auto;">
Hi this is container
</div>
<button id="addItem">
Click me
</button>
<script>
let element = document.getElementById('addItem');
let newElement = document.createElement('p');
let doc = document.getElementsByName('body');
element.onclick = function() {
newElement.innerText = "i am added using DOM";
document.getElementById('container').appendChild(newElement);
document.getElementById('container').style.border = "2px solid black"
}
element.ondblclick = function(){
document.getElementById('container').removeChild(newElement);
doc.style.backgroundColor = "black"
}
</script>
</body>
</html>