Why document.getelementbyId doesn't work in Firefox?
I can't figure out why document.getElementById doesn't work in Firefox:
document.getElementById("main").style.width = "100";
When I check Firebug it says:
TypeError: document.getElementById ("main") is null
Does anyone know why this is happening?
EDIT: Unfortunately the body element was a bad example. I changed it to another element with the id "main".
source to share
You have set the id of the element <body>
to "body":
<body id="body" ...>
Update:
Check if the following example works for you: http://jsbin.com/uyeca/edit Click the Output tab to see the output (which should be a 600px wide DIV).
source to share
https://developer.mozilla.org/En/DOM/Document.getElementById
Just create an element and assigning an ID will not result in an element accessible by getElementById. Instead, one needs to insert the element first into the document tree with an insert or similar, probably in a hidden div.
var element = document.createElement("div"); element.id = 'testqq'; var el = document.getElementById('testqq'); //
el will be null!
source to share