document.getElementsByTagName(“*”) Or document.all

前端 未结 6 488
盖世英雄少女心
盖世英雄少女心 2021-01-03 10:16

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

document.all works for IE/Chrom/S

6条回答
  •  有刺的猬
    2021-01-03 10:34

    Try like this:

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

    Or shorter version

    allElements = document.all ? document.all : document.getElementsByTagName("*");
    

提交回复
热议问题