- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to stop the execution of a function with JavaScript?
To stop the execution of a function in JavaScript, use the clearTimeout() method. This function call clears any timer set by the setTimeout() functions.
Example
You can try to run the following code to learn how to work with clearTimeout() method in JavaScript.
<html> <head> <title>JavaScript clearTimeout() method</title> <script> <!-- var imgObj = null; var animate ; function init(){ imgObj = document.getElementById('myImage'); imgObj.style.position= 'relative'; imgObj.style.left = '0px'; } function moveRight(){ imgObj.style.left = parseInt(imgObj.style.left) + 10 + 'px'; animate = setTimeout(moveRight,20); // call moveRight in 20msec } function stop(){ clearTimeout(animate); imgObj.style.left = '0px'; } window.onload = init; //--> </script> </head> <body> <form> <img id = "myImage" src = "/images/html.gif" /> <p>Click the buttons below to handle animation</p> <input type = "button" value = "Start" onclick = "moveRight();" /> <input type = "button" value = "Stop" onclick = "stop();" /> </form> </body> </html>
- Related Articles
- How to stop a function during its execution in JavaScript?
- How to stop Tkinter after function?
- How to stop a loop with a stop button in Tkinter?
- How can I stop a video with JavaScript in Youtube?
- How to display a SQL execution progress along with execution plan in Oracle?
- How to invoke a function with a function constructor in JavaScript?
- How to use comments to prevent JavaScript Execution?
- How to call jQuery function with JavaScript function?
- How to stop the loop for JavaScript scroll down?
- How to stop form submission using JavaScript?
- How to invoke a JavaScript Function with 'new' Function Constructor?
- How to stop refreshing the page on submit in JavaScript?
- A bus moves from stop A to stop B with a speed of 40 km/hr and then from stop B to stop A with a speed of 50 km/hr. What is its average speed ?
- How to invoke a function with partials appended to the arguments in JavaScript?
- How to execute a Javascript function in Python with Selenium?

Advertisements