Hide the Toast Message
Part of the JavaScript in Action section of Coddy's HTML journey — lesson 12 of 27.
Challenge
EasyHide the Toast After 3 Seconds.
We don’t want the toast message to stay forever, so let’s hide it after a short delay:
- Use
setTimeout()to create a 3-second delay. - Inside the timeout function, add the
"hidden"class to the toast element. - Also remove the
"show"class from the toast element so it disappears smoothly.
Try it yourself
<!DOCTYPE html>
<html>
<head>
<title>Form with Toast</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h2>Subscribe to our Newsletter</h2>
<form id="myForm">
<input type="text" id="name" placeholder="Enter your name">
<button type="submit">Submit</button>
</form>
</div>
<!-- Toast -->
<div id="toast" class="toast hidden">Form submitted successfully!</div>
<script src="script.js"></script>
</body>
</html>