I`m having trouble with some javascript and I think somebody here will be able to help :-D I'll give as much detail as i can.
My goal is to add a new dom element, specifically a div element to the body tag.
The code I write works fine in firefox but in ie i get the fairly common:
"internet explorer cannot open the internet site 'www.mysite.joe'
operation aborted"
I've read up and found that the most common cause (and i think the cause of my problem) is attempting to modify the dom before it has fully loaded. However I can't fnd a method of preventing the execution of the javascript that works. I've tried placing inline code in several different positions around the page, and also in an external file. I've tried implementing some of the things I've read about but I think I'm misunderstanding something fundamental which is making this extremely difficult to solve.
Here is the code which breaks my web page:
Code:
var addADiv = true;
var myDiv;
if(addADiv){
myDiv = document.createElement('div');
myDiv.setAttribute('id','myNewDiv');
myDiv.innerHTML = '<p>This is a new div element</p>';
document.body.appendChild(myDiv);
}
One last thing; I would prefer to avoid using Mootools if possible :-)
Thanks for reading
Joe
edit: Some of the above is wrong. Whether addADiv is true or false ie still gives the error. I commented out the code and then the page loaded in ie but the js still bugged. I added 'defer="defer"' to the script tag containing the code i posted and now as long as addADiv is false the page loads without any issues and all the javascript is executed as it should be. However this brings me back to what I mentioned above which is as soon as i set it to true internet explorer has a hissy fit and brings up that crazy message. This leads me to believe that defer="defer" doesn't actually defer the script for as long as i would like it to, that is of course presuming the cause of the issue is indeed the attempt to modify the dom before its finished loading...
Ok.. if you can follow that rambling and you've got this far thanks <3






















Linear Mode

