-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtoggleClass.html
49 lines (38 loc) · 1.01 KB
/
toggleClass.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
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#toggleBtn").click(function () {
$("h1, h2, p, div").toggleClass("green");
});
$("#addClassedBtn").click(function () {
$("h1, h2, p").addClass("blue");
$("div").addClass("important");
});
});
</script>
<style>
.green {
color: green;
}
.important {
font-weight: bold;
font-size: xx-large;
}
.blue {
color: blue;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<div>This is some important text!</div><br>
<button id="toggleBtn">Toggle class</button>
<button id="addClassedBtn">Add classes to elements</button>
</body>
</html>