Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions dom_manipulation/button.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
<!DOCTYPE html>
<html>
<head><title>JavaScript Button Example</title></head>

<body>
<head>
<title>Creative JavaScript Button Example</title>
</head>

<body>
<button id='squeeze'>Squeeze me</button>

<script>
let button = document.getElementById("squeeze");
function shout(){
alert("... and I squeak");
}
button.addEventListener("click", shout);
document.addEventListener("DOMContentLoaded", function () {
let button = document.getElementById("squeeze");

function changeColor() {
// Generate random values for RGB
let randomColor = 'rgb(' +
Math.floor(Math.random() * 256) + ',' +
Math.floor(Math.random() * 256) + ',' +
Math.floor(Math.random() * 256) + ')';

// Change the background color of the body
document.body.style.backgroundColor = randomColor;
}

button.addEventListener("click", changeColor);
});
</script>
</body>
</body>

</html>