-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (15 loc) · 809 Bytes
/
script.js
File metadata and controls
19 lines (15 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// A common pattern is to wait for the entire HTML document to load before running JS.
document.addEventListener('DOMContentLoaded', function() {
// 1. Get references to the HTML elements using their IDs
const button = document.getElementById('myButton');
const messageParagraph = document.getElementById('message');
// 2. Define the function that will run when the button is clicked
function changeText() {
messageParagraph.textContent = "🥳 The text has been successfully changed by JavaScript!";
// Optional: Disable the button after one click
button.disabled = true;
button.textContent = "Clicked!";
}
// 3. Attach the function to the button's click event
button.addEventListener('click', changeText);
});