I have a problem, I think it's quite common on javacript but can't figure what to search.
JSfeedle equivalent: https://jsfiddle.net/Draykoon/55jzr2uq/19/ feedle with solution thanks @Joe https://jsfiddle.net/Draykoon/55jzr2uq/20/
I want to change the color of an arrow when onclick, then execute some code and set the color back to the original one.
I use sleep as an example but it's a function wich takes time but don't know how many. consider this code:
function sleep(seconds)
{
var e = new Date().getTime() + (seconds * 1000);
while (new Date().getTime() <= e) {}
}
$('i.fa-chevron-circle-left').click(function(){
var id = $(this).attr("id");
$($("div.tab-pane")[id]).find("i.fa-chevron-circle-left").css("color","#ff9900");
sleep(1);
$($("div.tab-pane")[id]).find("i.fa-chevron-circle-left").css("color","#8BBE22");
});
the #ff9900 color is not showing on screen, it's like this line of code is skipped and worse when i don't reset the color to #8BBE22, the change only appears after the call to "sleep(1)", i want the user to be notified.
$('i.fa-chevron-circle-left').click(function(){
var id = $(this).attr("id");
$($("div.tab-pane")[id]).find("i.fa-chevron-circle-left").css("color","#ff9900");
sleep(1);
//color showing after 1 sec
});
I know the
$($("div.tab-pane")[id]).find("i.fa-chevron-circle-left")
is not proper,
I try
$("div.tab-pane:nth-child(" +(id+1).toString() + ")" + " i.fa-chevron-circle-left" )
I got the same result, the color changed but with a delay.
I think i am missing an important behaviour of javascript.
Sleep should be replace with a call to an other function, i don't know the time of execution (redraw a graph in reality)
Thanks in advance.