<!DOCTYPE html>
<html lang="en-US">
<body>
<p>Try to click the button before 3 sec to stop alert.</p>
<button onclick="myFunction()">End setTimeout</button>
<p id="point"></p>
<script>
var myTimeout = setTimeout(myMessage, 3000);
function myFunction(){
clearTimeout(myTimeout);
document.getElementById("point").innerHTML = "setTimeout Ended";
}
function myMessage(){
alert("I'm 3 seconds delay");
}
</script> </body>
</html>