Ad
Event Triggers Immediately After Reload. Not After "onclick"
On the way to my first Pomodoro-App (timer) shipwrecking with oncLick
, which should start the counter…
It starts even without beeing triggered by button click. How can I prevent that?
let display = document.getElementById("counter");
document.getElementById("ticker").onclick = function() {
timeChange(25);
};
// document.getElementById("ticker").addEventListener("click", function() {
// timeChange(25);
// });
function timeChange(seconds) {
// let seconds = 25;
seconds -= 1;
display.innerText = seconds;
page.firstChild.nodeValue = seconds;
if (seconds > 0) {
setTimeout(timeChange, 1000, seconds);
}
}
timeChange(25);
<body>
<div id="page">
<div id="counter"></div>
<button id="ticker">Start Pomodoro</button>
</div>
</body>
I already found an answer to the same(?) issue:
That's because you're assigning the result of executing rollDice(results) to your clickButton.onclick function
But I did not(?) assign the result of my function to onclick
Is it because of the argument (25) I put into the function to which the onclick
is assigned to?
Many thanks in advance
Ad
Answer
Remove:
timeChange(25);
from the bottom of your code
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad