• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Updating DOM Synchronously

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks in advance for your attention. The issue I'm having is that a call to document.getElementById("someElement").innerHTML does not appear to be executing synchronously. Here is simplified example code:


When executed in both IE and Firefox, the string "Processing..." does not appear -- it's as if the browser is ignoring the call and going directly to generateSomeHTML() function. Are DOM updates such as this done asynchronously? The reason I ask is because I can put an alert() at line #2 and the string "Processing..." will appear.

 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The display will not update until there is a break in activity. Something like an alert will cause this. A time-intensive operation will not. The display will not update until the operation completes and the function returns.

If it's really important to you -- really important, I'd never do this just for something like this -- you can use a timeout to cause a break between the code where you change the display, and the time-intensive operation executes.
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Bear. Haven't visited in a long time but I could always count on you before. I just happened to find a discussion a few minutes ago on this topic, and it came to the same conclusion!

Here is the link to the discussion to anyone interested: Force DOM Update.

 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic