I'm trying change text before I get feeds.
But the text changes after I got the feeds.
The question/answer it's only for Google Chrome (because it's an extension)
Sorry for my poor english ;-)
$("h1").click(function(){
$(this).text("Loading..."); // this happen after fids();
fids(); // function to get feeds
});
1 Answer 1
It would be better to change fids to work asynchronously, but if you can't do that, you can run fids in a timeout:
$("h1").click(function(){
$(this).text("Loading...");
setTimeout(fids, 0);
});
Try it on JSFiddle.
The reason it doesn't work the way you had it is that in all common browsers, JavaScript runs on the UI thread. If you change the text and then call a blocking function, the browser waits for the JavaScript to finish running before it updates the UI. Using setTimeout makes it run on the next event loop, after the browser has had time to redraw the text.