!– begin snippet js hide false console true babel false —
!– language lang-js —
suraj.js
var mins=.1;
var secs=mins60;
function countdown() {
setTimeout('Decrement()',60);
}
function Decrement() {
if(document.getElementById) {
minutes=document.getElementById(minutes);
seconds=document.getElementById(seconds);
if(seconds59) {
seconds.value=secs;
}
else {
minutes.value=getminutes();
seconds.value=getseconds();
}
if(mins1) {
minutes.style.color=red;
seconds.style.color=red;
}
if(mins0) {
alert('time up');
minutes.value=0;
seconds.value=0;
}
else {
secs--;
setTimeout('Decrement()',1000);
}
}
}
function getminutes() {
mins=Math.floor(secs60);
return mins;
}
function getseconds() {
return secs-Math.round(mins60);
}
!– language lang-html —
!DOCTYPE html
html xmlns=httpwww.w3.org1999xhtml
head
!--LINK external js--
script type=textjavascript src=suraj.js data-scriptid=MyDomScriptscript
!-- Link jquery --
script type=textjavascript src=httpajax.googleapis.comajaxlibsjquery1.7.1jquery.min.jsscript
head
body onload=countdown()!-- Your web--
button id=myBtnTry itbutton
div style=display flex; width80%;
justify-contentcenter; padding-top 0%;
Time Left
div
div style=display flex; width80%;
justify-contentcenter; padding-top 0%;
input id=minutes type=text style=width 3%; border none; font-size 16px;
font-weight bold; color black;
font size=5
font
input id=seconds type=text style=width 3%; border none; font-size 16px;
font-weight bold; color black;
div
script type=textjavascript
document.getElementById(myBtn).addEventListener(click, function() {
let domScripts = document.querySelectorAll('[data-scriptid=MyDomScript]');
domScripts.forEach(function(s) {
s.remove();
});
});
script
body
html
!– end snippet —
How can i stop the timer on button press that will destroy js imported…or any manual way?
I want to remove script tag from DOM && completely erase the variables or events already defined by the script.