• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Updating DOM Synchronously

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • 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.

 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.

 
Won't you be my neighbor? - Fred Rogers. tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic