javascript - Can I blindly replace all occurrences of document.all in my entire project with document.getElementsByTagName('*')? -
i'm working on lot of legacy code , have huge number of instances of document.all usage. need replace these instances (in bulk) microsoft supports (as understand document.all is not supported anymore).
is safe option replace instances of document.all document.getelementsbytagname()? please bear in mind document.all come in many flavours document.all.item("") etc.. need know if document.getelementsbytag('') work solution blind replacement of document.all wherever used (in whatever form)
from mdn page #document
document.all
provides access elements id. legacy, non-standard, interface , should usedocument.getelementbyid()
method instead.
therefore, no document.getelementsbytagname("*")
return more elements elements id
this definition means do
document.queryselectorall('[id]'); // nodelist
however
the all collection includes 1 element object each valid html tag. if valid tag has matching end tag, both tags represented same element object.
in case true document.getelementsbytagname("*")
gives similar result (htmlcollection)
however, again
the nodelist fail reproduce expected result of document.all.id_value
, document.all[id_value]
or document.all(foo)
.
the htmlcollection support document.all.id_value
, document.all[id_value]
described in w3's dom spec, though recommend against use of on other methods such getelementbyid
really, you're going have go through code make sure work expected whichever alternative choose.
Comments
Post a Comment