0
<button onClick="increase = setInterval(increasing, 400);
        clearInterval(decrease);"><b>Sicaklik Arttir (+)</b>
</button>

<button onClick="clearInterval(increase);
        clearInterval(decrease);"><b>Stop</b
</button>

<button onClick="decrease = setInterval(decreasing, 400);
        clearInterval(increase)"><b>Sicaklik Azalt  (-)</b>
</button>

I have buttons that include setInterval. When I press button, setInterval is called, but when I press again, setInterval is called again, and I can't stop it.

How do I stop it?

I want to run setInterval only one time.

2 Answers 2

2

There is setTimeout method which calls only once at a time.

setTimeout(increasing, 400)

To clear the timeout use clearTimeout method.

Sign up to request clarification or add additional context in comments.

1 Comment

how can I use setTimeout? Can you expalin please
0

Check the return value before button clicked 2nd time and before timeout of 400 seconds ,

 if(! increase)
   increase = setTimeout(increasing, 400);

Then clear timeout :

 clearTimeout(increase);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.