Why is document.all.item not working on localhost?
I am working on a very old web application that uses document.all.item to iterate through the dom and it throws runtime errors when I deploy the application to localhost and the error goes away when I deploy it to a server outside of my machine. Below is the code where it throws an unknown runtime error. what is the reason or how can i solve it?
with(document.all)
item('fieldName').innerHTML = "Blah Blah"; // Error is on this line.?
}
When I tried to debug IE. I can access the element, but for some reason I cannot access the innerHTML. Is it because of IE or something else?
source to share
On Google Chrome HTMLAllCollection
(result document.all
) has no property item
. I suggest going through them with a loop for
:
var items = document.all;
var length = items.length;
for(var i = 0; i < length; i++){
//Do something with: items[i];
}
The change in behavior could be due to an inconsistent implementation of the property item
on HTMLAllCollection
s, where IE appears to implement it and your server does not.
source to share