x
1
2
<html>
3
<head>
4
<title>CloseTag | JavaScript DOM ClassList | add</title>
5
<style>
6
.heading
7
{
8
background-color:#007bff;
9
padding:10px;
10
color:white;
11
}
12
</style>
13
</head>
14
<body>
15
<h1>JavaScript DOM ClassList add</h1>
16
17
<p id="h1" class="abc xyz">this element contains some classes ["abc","xyz"]<p>
18
19
<script>
20
let h1 = document.getElementById("h1");
21
/* classes before add */
22
console.log(h1.classList);
23
h1.classList.add('heading');
24
/* classes after add */
25
console.log(h1.classList);
26
</script>
27
28
</body>
29
</html>