Skip to content

Instantly share code, notes, and snippets.

@pligor
Last active February 10, 2023 15:49
Show Gist options
  • Save pligor/9121fa7c6ad7144140124c4a168ce56f to your computer and use it in GitHub Desktop.
Save pligor/9121fa7c6ad7144140124c4a168ce56f to your computer and use it in GitHub Desktop.
btn_appear_disappear
<script src="script.js" />
<div>Ok</div>
// 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