A Pen by George Pligoropoulos on CodePen.
Last active
February 10, 2023 15:49
-
-
Save pligor/9121fa7c6ad7144140124c4a168ce56f to your computer and use it in GitHub Desktop.
btn_appear_disappear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="script.js" /> | |
<div>Ok</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set the time in milliseconds for how long the button should appear | |
const buttonTimeout = 3000; | |
// Set the time in milliseconds for how long the button should disappear after being clicked | |
const hideTimeout = 7000; | |
// Create the button element | |
const button = document.createElement("button"); | |
// Make the button appear after a few seconds | |
setTimeout(function() { | |
button.style.display = "block"; | |
button.innerHTML = "Hi Me"; | |
button.id = 'mybutton'; | |
// Add a click event listener to the button | |
button.addEventListener("click", function() { | |
console.log("Button was clicked!"); | |
}); | |
// Add the button to the page | |
document.body.appendChild(button); | |
}, buttonTimeout); | |
setTimeout(function() { | |
button.style.display = "none"; | |
button.parentNode.removeChild(button); | |
}, hideTimeout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment