Reputation:
I mean if I append some contents like this:
<body>
//contents
<script>body.appendChild('<img src="new.png">');
// other contents
</body>
the browser will fire window.onload considering only the original html or it will take in consideration the load of the new image too? (new.png
) ?
Upvotes: 0
Views: 212
Reputation: 490647
Besides that code/markup being incorrect, it will consider the new image. To append it to the DOM will be to download whatever the src
attribute points to.
However, if this code was placed inside of a window.onload = function() { ... }
, then it wouldn't be considered because its download would not occur until your window was loaded.
Here is the code that would actually work...
var img = new Image;
img.src = 'http://www.gravatar.com/avatar/3535689c965d66db3d2a936ced96192a?s=32&d=identicon&r=PG';
img.alt = 'Example';
document.body.appendChild(img);
Upvotes: 2