22 01 2010
document.getElementById() in MSIE
Ok, I think I screwed up somewhere – what I paste below breaks in all browsers, not just IE – if the getElementById is wrapped in a function and THEN called sometime after “OnLoad” is triggered, it works. Oh well…
Original Article –
This is strange. I have an issue which I have grossly simplified in order to explain the situation. Below are two snippets of code which work perfectly fine in all browsers but IE. The second code snippet gives the error message:
Message: ‘document.getElementById(…)’ is null or not an object
As you can see, the difference is that the javascript code is outside of the head tag and after the referenced div tag. Here’s the code that works in everything:
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" ><br><head><br><br></head><br><br><body><br><div id="boo"><br></div><br><script language="JavaScript"><br><!--<br>document.getElementById("boo").innerHTML = "boooo!";<br>//--><br></script><br></body><br></html> |
And here’s the code that breaks MSIE:
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" ><br><head><br><script language="JavaScript"><br><!--<br>document.getElementById("boo").innerHTML = "boooo!";<br>//--><br></script><br></head><br><br><body><br><div id="boo"><br></div><br><br></body><br></html><br> |
Does anyone have a scoobie how to get around this?
document.getElementById() in MSIE Sharepoint – Moving Webs from a Parent Web to another Parent Web
This comment has been removed by a blog administrator.