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
});
It would be better to change
fidsto work asynchronously, but if you can’t do that, you can runfidsin a timeout: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
setTimeoutmakes it run on the next event loop, after the browser has had time to redraw the text.