I am completely new in javascript and jquery ... I searched, but cannot find the answer to my problem ...
I need to stop a function that calls itself at the end (I read that this is called a recursive function)
So my html
<div id="slide_show"></div>
<a href="#" class="stop">Stop</a>
My js
$(function() {
moveSlide(true);
});
function moveSlide(repeat) {
if(repeat === true) {
$('#slide_show').slideToggle('slow',function() {
setTimeout(function() {
moveSlide(true);
},2000);
});
} else {
return;
}
}
$(document).on('click','.stop',function(e) {
e.preventDefault();
moveSlide(false);
});
The function is called forever, but I want to stop the repeat function when I press the button
What am I doing wrong?
source
share