pxlxgstzhk
New Member
I am implementing a Stopwatch in JavaScript.I want to delete additional div elements when pushing a \[code\]clear\[/code\] button. I added function \[code\]cc();\[/code\], but \[code\]function cc()\[/code\] doesn't work. What's wrong with my code?Javascript:\[code\]a = 0;myButton = 0;function myWatch(flug) { if(myButton == 0) { Start = new Date(); myButton = 1; document.myForm.myFormButton.value = "http://stackoverflow.com/questions/15457411/Stop!"; myInterval = setInterval("myWatch(1)", 1); } else { if(flug == 0) { myButton = 0; document.myForm.myFormButton.value = "http://stackoverflow.com/questions/15457411/Start"; clearInterval(myInterval); } Stop = new Date(); T = Stop.getTime() - Start.getTime(); H = Math.floor(T / (60 * 60 * 1000)); T = T - (H * 60 * 60 * 1000); M = Math.floor(T / (60 * 1000)); T = T - (M * 60 * 1000); S = Math.floor(T / 1000); Ms = T % 1000; document.myForm.myClick.value = http://stackoverflow.com/questions/15457411/H +":" + M + ":" + S + ":" + Ms; }}b = 0;function stop() { b++; stopa();}function stopa() { var element = document.createElement('div'); element.id = pos; var objBody = document.getElementsByTagName("body") .item(0); objBody.appendChild(element); rap = ""; rap = "rap" + b + "=" + H + ":" + M + ":" + S + ":" + Ms; element.innerHTML = rap;}function cc() { document.body.removeChild(element);}\[/code\]HTML:\[code\]<form name="myForm" action="#"> <input type="text" size="20" name="myClick"> <input type="button" value="http://stackoverflow.com/questions/15457411/Start" name="myFormButton" onclick="myWatch(0)" /> <input type="button" value="http://stackoverflow.com/questions/15457411/Rap" name="Rap" onclick="stop()"> <input type="button" value="http://stackoverflow.com/questions/15457411/clear" name="clear" onclick="cc()"></form><h3> <div id="pos"> </div></h3>\[/code\]