Reputation: 401
I am using document.all.item("name")
and it works in IE 10 and Google Chrome 29 but not in Firefox. Is there a replacement that is compatible with Firefox?
Upvotes: 2
Views: 8327
Reputation: 961
I know this is pretty old thread which I happened to stumble upon today. A fact we need to consider in replacing document.all.item
with document.getElementByName
is that former returns HTMLCollection
while latter returns NodeList
. Here is another SO thread discussing the differences between these two.
Upvotes: 0
Reputation: 2584
function findelement(name) {
if (document.getElementsByName(name))
return document.getElementsByName(name) ;
else
return document.getElementById(name) ;
}
Upvotes: 0
Reputation: 324780
document.getElementsByName("name")
should do the same thing, but better because it handles the case where there are multiple elements with the same name properly (ie. radio buttons, form arrays, etc.)
Upvotes: 1