Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.getElementsByTagName("*") Or document.all

document.getElementsByTagName("*") works for IE/Firefox/Opera, But doesn't work for Chrome and Safari.

document.all works for IE/Chrom/Safari, But doesn't work for Firefox.

How can I deal with it?

like image 266
Jason Avatar asked Oct 30 '25 06:10

Jason


1 Answers

Try like this:

if (document.all !== undefined)
{
   allElements = document.all;
}
else
{
   allElements = document.getElementsByTagName("*");
}

Or shorter version

allElements = document.all ? document.all : document.getElementsByTagName("*");
like image 112
kjagiello Avatar answered Oct 31 '25 19:10

kjagiello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!