-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1(change_background).html
More file actions
60 lines (52 loc) · 1.72 KB
/
project1(change_background).html
File metadata and controls
60 lines (52 loc) · 1.72 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
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>change background</title>
</head>
<body>
<button onclick="background()" class="button" id="button">Click Me</button>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: #ff70fb;
}
.button{
border: 0;
background-color: #1eff44;
border-radius: 5px;
padding: 10px 20px;
display: block;
margin: 2rem auto;
font-family: sans-serif;
outline: none;
cursor: pointer;
font: 1em sans-serif;
color: blue;
}
#button {
text-decoration: none;
}
.button:hover {
background-color: #ff70fb;
transition: 1s;
}
</style>
<script>
function background() {
alert("It is working");
//to target an element by class you have to use index of it like in this case [0]
document.getElementsByClassName("button")[0].style.color = "white";
//you also have to use index in tagname
document.getElementsByTagName("body")[0].style.backgroundColor = "black";
//you don't have to use index in id as id is unique
document.getElementById("button").style.textDecoration = "underline";
}
</script>
</body>
</html>