Why is document.getelementbyId not working in Firefox?
Solution 1
Did you set the id of the <body>
element 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 result (which should be a DIV with width 600px).
Solution 2
put your script before
</body>
Or, if you use your script in <head>
you may change code:
$(document).ready(function() {
//enter code here.
});
Solution 3
https://developer.mozilla.org/En/DOM/Document.getElementById
Simply creating an element and assigning an ID will not make the element accessible by getElementById. Instead one needs to insert the element first into the document tree with insertBefore or a similar method, probably into a hidden div.
var element = document.createElement("div"); element.id = 'testqq'; var el = document.getElementById('testqq'); //
el will be null!
chris
Updated on June 04, 2022Comments
-
chris almost 2 years
I can't figure out why document.getElementById is not working in Firefox:
document.getElementById("main").style.width = "100";
When I check in Firebug it says:
TypeError: document.getElementById("main") is null
Does anybody know why this is happening?
EDIT: Unfortunately, the "body" element was a bad example. I changed it to another element with an id of "main".