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

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

    document.all should be avoided as it is not Standards compliant. Instead you can use document.getElementById() for Particular Node or use $("*") For selecting all the elements using jQuery.

    But still if you would like to use document.all then see to it that Tag is removed from your page, as well as the xmlns attribute is also removed from your tag.

    Change anything like this:

    
    
    

    to:

    
    

    I have tested it on FireFox 19.0.2 and document.all works fine for me.

    The reason: When you use the tag you are telling the browser that your webpage is complaint with the standards which tells you to NOT use the document.all in your script, so the browser also does not allow it.

    But as you want to use it, you are obviously not following the standards so don't even bother to add the tag otherwise document.all won't work.

提交回复
热议问题