1

i am trying to appendChild() on an existing form, and its not working. i wonder if i need to delay the page, at least i thought i read that somewhere. what i am thinking is dynamically altering window onload to be a delay. do i grab the body tag like any other DOM element?

4

3 回答 3

3

Does this work?

window.addEventListener('load', function() {
    // Code to execute when DOM is loaded
}, false);

Steve

于 2009-04-16T21:42:11.213 回答
1

you could use a timeout to delay the call to your method that does the appendChild()...

setTimeout(functionName, 200)

If you are using jQuery you can use the ready method to delay your code until the page is fully loaded:

$(document).ready(function() {
    appendChild();
});

Edit: Removed quotes around function call in setTimeout per Steve's suggestion in the comments

于 2009-04-16T21:41:40.090 回答
0

the body-element is referenced directly under document,

document.body

But your question is very fuzzy.

If you call your DOM-manipulation from the onload-event, the DOM should be completely loaded. Therefor I assume a delay isn't the way to go.

于 2009-04-16T21:41:40.573 回答