I want to make the div fadeIn and fadeOut after every 2 seconds, but the setTimeout function is running only once and hiding the div, but that is it. It is not doing it more than once:
HTML:
<a href="javascript:void(0);">Pyp1</a>
<div id="disable">
Hello!
</div>
JavaScript (jQuery):
$(document).ready(function(){
setTimeout(function() {
$('#disable').toggle('fast');
}, 2000);
});
However, when I write the same thing for the click event, it actually works:
$(document).ready(function(){
$('a').click(function() {
$('#disable').fadeToggle('fast')
});
});
I've tried searching around (in Stack Overflow as well) and couldn't get the answer, I tried the click approach and it worked, but that is not the result I am looking for.
Where exactly is the problem and how may I fix it?