"Brian" wrote
Quote:
insertBefore method. I added a function to the mktree.js script, but
it failed to insert the button I created. However, Firefox's javscript
console did not report an error. AFAICS, it didn't find the element
with id="root".
I made a second page, this time putting the script to insert the
button inside the page itself, and it worked. I'm confused why the
funtion fails in the external js file, not inside the html document.
The test cases can be found here: http://www.tsmchughs.com/test/insert/ |
Simple. In your external file the code responsible for adding the button is
called before the page renders, before there is an element with id=root. Run
it onload and you should be fine. In the internal version, the button code
is placed at the end, when the element is there already.
Also,
newButton = document.createElement("BUTTON");
newButton.setAttribute("type", "button");
seems odd. What other type can a button be?
HTH
Ivo