1<!DOCTYPE html>
2<html>
3
4<head>
5 <title>JS DOMContentLoaded Event</title>
6 <script>
7 document.addEventListener('DOMContentLoaded', () => {
8 let btn = document.getElementById('btn');
9 btn.addEventListener('click', () => {
10 // handle the click event
11 console.log('clicked');
12 });
13 });
14 </script>
15</head>
16
17<body>
18 <button id="btn">Click Me!</button>
19</body>
20
21</html>
22Code language: HTML, XML (xml)