How can I make my modal open automatically after 5 seconds?

document.getElementById('button').addEventListener("click", function() {
	document.querySelector('.bg-modal').style.display = "flex";
});

document.querySelector('.close').addEventListener("click", function() {
	document.querySelector('.bg-modal').style.display = "none";
});

If this is how you are making it appear:

document.querySelector('.bg-modal').style.display = "flex";

Then you need to use the setTimeout function. It takes the function you want to run as the first param and the time delay as the second. So:

setTimeout(function() {
  console.log('See! I was called after 5000 milliseconds!);
  document.querySelector('.bg-modal').style.display = "flex";
}, 5000);
1 Like

like that, but with a closed quote in the console.log. :wink:

1 Like

thanks so much awesome answer thanks