• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • 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: 67747
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.

 
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic