jQuery .each and setTimeout is not working










1















I am trying to get some attar vale from an active slider. I have used each and setTimeout function. Initially, that worked. But after some time the slider stops if I use this code. Note this code is independent of the slider code.



function checkForChanges() 
$('#ninja-slider ul li').each(function(i)
if ($(this).hasClass("ns-show"))
//$(this).css("color", "red");
console.log('yes')
else
setTimeout(checkForChanges, 3000);
console.log('no')

);


$(checkForChanges);









share|improve this question
























  • $(checkForChanges) didn't call target function

    – Mohammad
    Nov 13 '18 at 11:03






  • 1





    Use checkForChanges(); instead

    – Zakaria Acharki
    Nov 13 '18 at 11:07











  • Slider normally work. But when I use this function slider stop working. wiregraph.com/dev @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:14












  • Also the console is showing the number of request is too much - prnt.sc/lhrw7r @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:18











  • That because your calling a recursive function that will not stop until all the li's has the ns-show class

    – Zakaria Acharki
    Nov 13 '18 at 11:21
















1















I am trying to get some attar vale from an active slider. I have used each and setTimeout function. Initially, that worked. But after some time the slider stops if I use this code. Note this code is independent of the slider code.



function checkForChanges() 
$('#ninja-slider ul li').each(function(i)
if ($(this).hasClass("ns-show"))
//$(this).css("color", "red");
console.log('yes')
else
setTimeout(checkForChanges, 3000);
console.log('no')

);


$(checkForChanges);









share|improve this question
























  • $(checkForChanges) didn't call target function

    – Mohammad
    Nov 13 '18 at 11:03






  • 1





    Use checkForChanges(); instead

    – Zakaria Acharki
    Nov 13 '18 at 11:07











  • Slider normally work. But when I use this function slider stop working. wiregraph.com/dev @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:14












  • Also the console is showing the number of request is too much - prnt.sc/lhrw7r @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:18











  • That because your calling a recursive function that will not stop until all the li's has the ns-show class

    – Zakaria Acharki
    Nov 13 '18 at 11:21














1












1








1








I am trying to get some attar vale from an active slider. I have used each and setTimeout function. Initially, that worked. But after some time the slider stops if I use this code. Note this code is independent of the slider code.



function checkForChanges() 
$('#ninja-slider ul li').each(function(i)
if ($(this).hasClass("ns-show"))
//$(this).css("color", "red");
console.log('yes')
else
setTimeout(checkForChanges, 3000);
console.log('no')

);


$(checkForChanges);









share|improve this question
















I am trying to get some attar vale from an active slider. I have used each and setTimeout function. Initially, that worked. But after some time the slider stops if I use this code. Note this code is independent of the slider code.



function checkForChanges() 
$('#ninja-slider ul li').each(function(i)
if ($(this).hasClass("ns-show"))
//$(this).css("color", "red");
console.log('yes')
else
setTimeout(checkForChanges, 3000);
console.log('no')

);


$(checkForChanges);






javascript jquery settimeout each






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 11:54









Zakaria Acharki

55.6k134368




55.6k134368










asked Nov 13 '18 at 10:51









Imtiaz ShamimImtiaz Shamim

273




273












  • $(checkForChanges) didn't call target function

    – Mohammad
    Nov 13 '18 at 11:03






  • 1





    Use checkForChanges(); instead

    – Zakaria Acharki
    Nov 13 '18 at 11:07











  • Slider normally work. But when I use this function slider stop working. wiregraph.com/dev @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:14












  • Also the console is showing the number of request is too much - prnt.sc/lhrw7r @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:18











  • That because your calling a recursive function that will not stop until all the li's has the ns-show class

    – Zakaria Acharki
    Nov 13 '18 at 11:21


















  • $(checkForChanges) didn't call target function

    – Mohammad
    Nov 13 '18 at 11:03






  • 1





    Use checkForChanges(); instead

    – Zakaria Acharki
    Nov 13 '18 at 11:07











  • Slider normally work. But when I use this function slider stop working. wiregraph.com/dev @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:14












  • Also the console is showing the number of request is too much - prnt.sc/lhrw7r @ZakariaAcharki

    – Imtiaz Shamim
    Nov 13 '18 at 11:18











  • That because your calling a recursive function that will not stop until all the li's has the ns-show class

    – Zakaria Acharki
    Nov 13 '18 at 11:21

















$(checkForChanges) didn't call target function

– Mohammad
Nov 13 '18 at 11:03





$(checkForChanges) didn't call target function

– Mohammad
Nov 13 '18 at 11:03




1




1





Use checkForChanges(); instead

– Zakaria Acharki
Nov 13 '18 at 11:07





Use checkForChanges(); instead

– Zakaria Acharki
Nov 13 '18 at 11:07













Slider normally work. But when I use this function slider stop working. wiregraph.com/dev @ZakariaAcharki

– Imtiaz Shamim
Nov 13 '18 at 11:14






Slider normally work. But when I use this function slider stop working. wiregraph.com/dev @ZakariaAcharki

– Imtiaz Shamim
Nov 13 '18 at 11:14














Also the console is showing the number of request is too much - prnt.sc/lhrw7r @ZakariaAcharki

– Imtiaz Shamim
Nov 13 '18 at 11:18





Also the console is showing the number of request is too much - prnt.sc/lhrw7r @ZakariaAcharki

– Imtiaz Shamim
Nov 13 '18 at 11:18













That because your calling a recursive function that will not stop until all the li's has the ns-show class

– Zakaria Acharki
Nov 13 '18 at 11:21






That because your calling a recursive function that will not stop until all the li's has the ns-show class

– Zakaria Acharki
Nov 13 '18 at 11:21













1 Answer
1






active

oldest

votes


















0














If you want to get the active slider every 3 seconds so no need for each it could be like :



function checkForChanges() 
//Here is the active li in the slide
var active_li = $("#ninja-slider li.ns-show");

//Get the src of shwon image
console.log( $("#ninja-slider li.ns-show").find('img').attr('src') );

setTimeout(checkForChanges, 3000);


checkForChanges();





share|improve this answer























  • That worked. Thank you @Zakaria Acharki

    – Imtiaz Shamim
    Nov 13 '18 at 12:10











  • You're welcome, glad I could help.

    – Zakaria Acharki
    Nov 13 '18 at 13:52










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279369%2fjquery-each-and-settimeout-is-not-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you want to get the active slider every 3 seconds so no need for each it could be like :



function checkForChanges() 
//Here is the active li in the slide
var active_li = $("#ninja-slider li.ns-show");

//Get the src of shwon image
console.log( $("#ninja-slider li.ns-show").find('img').attr('src') );

setTimeout(checkForChanges, 3000);


checkForChanges();





share|improve this answer























  • That worked. Thank you @Zakaria Acharki

    – Imtiaz Shamim
    Nov 13 '18 at 12:10











  • You're welcome, glad I could help.

    – Zakaria Acharki
    Nov 13 '18 at 13:52















0














If you want to get the active slider every 3 seconds so no need for each it could be like :



function checkForChanges() 
//Here is the active li in the slide
var active_li = $("#ninja-slider li.ns-show");

//Get the src of shwon image
console.log( $("#ninja-slider li.ns-show").find('img').attr('src') );

setTimeout(checkForChanges, 3000);


checkForChanges();





share|improve this answer























  • That worked. Thank you @Zakaria Acharki

    – Imtiaz Shamim
    Nov 13 '18 at 12:10











  • You're welcome, glad I could help.

    – Zakaria Acharki
    Nov 13 '18 at 13:52













0












0








0







If you want to get the active slider every 3 seconds so no need for each it could be like :



function checkForChanges() 
//Here is the active li in the slide
var active_li = $("#ninja-slider li.ns-show");

//Get the src of shwon image
console.log( $("#ninja-slider li.ns-show").find('img').attr('src') );

setTimeout(checkForChanges, 3000);


checkForChanges();





share|improve this answer













If you want to get the active slider every 3 seconds so no need for each it could be like :



function checkForChanges() 
//Here is the active li in the slide
var active_li = $("#ninja-slider li.ns-show");

//Get the src of shwon image
console.log( $("#ninja-slider li.ns-show").find('img').attr('src') );

setTimeout(checkForChanges, 3000);


checkForChanges();






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 11:52









Zakaria AcharkiZakaria Acharki

55.6k134368




55.6k134368












  • That worked. Thank you @Zakaria Acharki

    – Imtiaz Shamim
    Nov 13 '18 at 12:10











  • You're welcome, glad I could help.

    – Zakaria Acharki
    Nov 13 '18 at 13:52

















  • That worked. Thank you @Zakaria Acharki

    – Imtiaz Shamim
    Nov 13 '18 at 12:10











  • You're welcome, glad I could help.

    – Zakaria Acharki
    Nov 13 '18 at 13:52
















That worked. Thank you @Zakaria Acharki

– Imtiaz Shamim
Nov 13 '18 at 12:10





That worked. Thank you @Zakaria Acharki

– Imtiaz Shamim
Nov 13 '18 at 12:10













You're welcome, glad I could help.

– Zakaria Acharki
Nov 13 '18 at 13:52





You're welcome, glad I could help.

– Zakaria Acharki
Nov 13 '18 at 13:52

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279369%2fjquery-each-and-settimeout-is-not-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo