jQuery .each and setTimeout is not working
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
|
show 2 more comments
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
$(checkForChanges)
didn't call target function
– Mohammad
Nov 13 '18 at 11:03
1
UsecheckForChanges();
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 theli
's has thens-show
class
– Zakaria Acharki
Nov 13 '18 at 11:21
|
show 2 more comments
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
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
javascript jquery settimeout each
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
UsecheckForChanges();
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 theli
's has thens-show
class
– Zakaria Acharki
Nov 13 '18 at 11:21
|
show 2 more comments
$(checkForChanges)
didn't call target function
– Mohammad
Nov 13 '18 at 11:03
1
UsecheckForChanges();
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 theli
's has thens-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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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();
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
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
add a comment |
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();
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
add a comment |
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();
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();
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$(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 thens-show
class– Zakaria Acharki
Nov 13 '18 at 11:21