javascript - Cannot read property 'parentNode' of null. Error i get in console -
var button1 = document.getelementbyid("start"); var button2 = document.getelementbyid("stop"); var timegraph = document.getelementbyid("ceas"); var lapbutton = document.getelementbyid("lap"); var lame = document.getelementbyid("test"); var time = 0; var resetstart = 0; var myinterval; var body = document.getelementbyid("body"); var action = document.getelementbyid("lappara"); function start() { if (resetstart == 0) { resetstart = 1; running(); button1.innerhtml = "pause"; } else { resetstart = 0; button1.innerhtml = "resume"; clearinterval(myinterval); } } function reset() { time = 0; resetstart = 0; button1.innerhtml = "start"; timegraph.innerhtml = "00:00:00:00"; clearinterval(myinterval); var aux = action.parentnode; aux.removechild(action); } function ongoing() { time++; var hours = math.floor(time / 100 / 60 / 60); var minutes = math.floor(time / 100 / 60 % 60); var seconds = math.floor(time / 100 % 60); var hundreds = math.floor(time / 10 % 10); var thousands = time % 10; if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } timegraph.innerhtml = hours + ":" + minutes + ":" + seconds + ":" + hundreds + thousands; } function running() { if (resetstart == 1) { myinterval = setinterval(ongoing, 10); } else { timegraph.innerhtml = "00:00:00:00"; } } function lap() { var n = document.createelement("p"); n.setattribute("id", "lappara"); var text = document.createtextnode(timegraph.innerhtml); n.appendchild(text); body.insertbefore(n, action); }
whenever call reset() function error above. code supposed stopwatch , lap() function creates laps. looked solutions none seemed work. please me if can
i assume can call reset()
once next time call error appears. because of aux.removechild(action)
. delete action
, try it's parentnode - that's problem is.
Comments
Post a Comment