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

前端 未结 6 494
盖世英雄少女心
盖世英雄少女心 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:24

    While I would not encourage you to do a document.all because it implies you are doing a lot of client-side parsing that is just not needed I do understand there is a lot of legacy stuff out there etc. I wanted to post a little extension of my thoughts on a wrapper method for document.all.

    document.all = document.all || function(){
       return document.getElementsByTagName("*");
    };
    

    Of course this assumes you have a getElementsByTagName function, which should be the case.

提交回复
热议问题