-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.html
57 lines (54 loc) · 1.78 KB
/
dom.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
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM - Document Object Model</title>
</head>
<body>
<button>9a</button>
<button class="bBtn">9b</button><br><br>
<button class="bBtn1" onclick="display('heads')">heads</button>
<button class="bBtn2" onclick="display('tails')">tails</button>
<p class="displayHere"></p>
<br>
<input placeholder="Enter Name" class="nameInp" onkeydown="takeName(event)">
<button onclick="getName()">Submit</button>
<p class="displayName"></p>
<input placeholder="Enter Name" class="instantInp" onkeyup="myFun()">
<p class="showHere"></p>
<script>
//document.body.innerHTML = "Hello Niya"; //will remove everything on the page and will display text hello
/*console.log(document.querySelector('button'));
console.log(document.querySelector('button').innerHTML);
console.log(document.querySelector('button')
.innerHTML = 'Change');
*/
console.log(document.querySelector('button'));
console.log(document.querySelector('.bBtn').innerHTML = '9b done!');
function display(option){
if(option === 'heads'){
document.querySelector('.displayHere').innerHTML = 'You Choose: Heads';
}else{
document.querySelector('.displayHere').innerHTML = 'You Choose: Tails';
}
}
function takeName(event){
if(event.key === 'Enter'){
getName();
}
}
function getName(){
const disName = document.querySelector('.nameInp');
let valueName = disName.value;
document.querySelector('.displayName')
.innerHTML = `Your Name is ${valueName}.`
}
function myFun(){
const x = document.querySelector('.instantInp');
let y = x.value;
document.querySelector('.showHere').innerHTML = y;
}
</script>
</body>
</html>