Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  195] [ 6]  / answers: 1 / hits: 20780  / 13 Years ago, wed, august 24, 2011, 12:00:00

I'm just getting started with d3.js and there is one detail which is completely eluding me: how do I have my code execute only after the DOM is ready to receive input?



I could, of course, use something like jQuery but that seems excessive.



In every d3.js example I've encountered there seems to be no special document.onReady() type of routine, yet all the examples work flawlessly. When testing code on my end, however, the code totally fails if executed before the DOM is ready (throwing my code into a window.onload confirms this).



What gives?


More From » d3.js

 Answers
72

You'll notice in their examples that their javascript is below any of the html elements that is utilized so that part of the dom is loaded before it starts executing the javascript.



Simply putting your javascript at the bottom of the body is usually good enough.


[#90456] Monday, August 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
xochitl

Total Points: 559
Total Questions: 95
Total Answers: 117

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
xochitl questions
;