I am trying to really understand the details of how a browser loads a webpage.
I have two javascript statements in a .js file attached to an HTML file:
d3.select("body").append("span").text("Hello, world!");
alert("huh?");
When I load the page, I see an alert "huh." So the "huh" statement fires.
However "Hello, world" is not appended to the document body.
If I then go and run d3.select("body").append("span").text("Hello, world!")
in the console then it executes as expected--i.e. it adds "Hello, world" to the body.
What's going on here? alert("huh?")
fires after the window.onload event in the DOM, correct? But d3.select...
does not fire?
Why the discrepancy?