index.html
script.js
setup.css
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="/assets/styles/reset.css" rel="stylesheet"> <link href="setup.css" rel="stylesheet"> <script defer src="script.js"></script> </head> <body> <button id="example">Click here!</button> </body> </html>
// Set up a variable for our button! let button = document.querySelector('#example'); // Any CSS selector. button.onclick = () => { // Attach the click event. alert('The button was clicked!'); // Pop an alert! };
html, body { height: 100%; } body { --base: 20px; align-items: center; display: flex; font-family: sans-serif; justify-content: center; padding: var(--base); } button { background-color: deepskyblue; border-radius: calc(var(--base) / 2); cursor: pointer; /* Show the Mickey-Mouse hand! */ padding: calc(var(--base) / 2); }