document.getElementsByTagName("*") It works for IE/FF/Opera, But doesn't work for Chrom and Safari
document.all works for IE/Chrom/Safari, But doesn't work for FF.
How can I deal with it?
Many thanks
document.getElementsByTagName("*") It works for IE/FF/Opera, But doesn't work for Chrom and Safari
document.all works for IE/Chrom/Safari, But doesn't work for FF.
How can I deal with it?
Many thanks
I admit that there might be technologies today I don't know about that allow for this sort of thing to be done in cross-browser format, but the way I've always had to do it in the past is to have a check of some sort for which browser you're using.
A simpler solution, though, is to try to run one of them, and if you get nothing/null/an error, use the other.
Anyway, if you really don't want to deal with it yourself, you should use a library that will deal with it for you (e.g., jQuery).
Try like this:
if (document.all)
{
allElements = document.all;
}
else
{
allElements = document.getElementsByTagName("*");
}
Or shorter version
allElements = document.all ? document.all : document.getElementsByTagName("*");
document.getElementsByTagName()
works perfectly in all modern browsers (everything newer than IE5).
If it doesn't seem to work in Chrome or Safari, then it's most likely just a symptom of an error you have elsewhere.