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

document.getElementsByTagName("*") works for IE / Firefox / Opera, but does not work for Chrome and Safari.

document.all works for IE / Chrom / Safari, but does not work for Firefox.

How can I handle this?

+3
source share
6 answers

document.allshould be avoided as this is not up to standard. Instead, you can use document.getElementById()to Private Node or use $("*")To select all elements using jQuery.

However, if you want to use document.all, then make sure the tag is <!DOCTYPE>removed from your page, and the xmlns attribute is also removed from your tag <html>.

- :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<html>

FireFox 19.0.2 document.all .

:. <!DOCTYPE>, , - , , document.all script, .

, , , , <!DOCTYPE>, document.all .

-1

:

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

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

document.getElementsByTagName() (, IE5).

Chrome Safari, , .

+3

, , , - , , , - - , .

, /null/, .

, , , (, jQuery).

0

document.all, , , . , .. wrapper document.all.

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

, , getElementsByTagName, .

0

@Khurram Hassan, .

-, . ( , , ) document.getElementsByTagName( "*" ), Chrome. google.com Google Chrome , 356 . , html, head, body , , , , . Opera, Chrome, JavaScript, , .

-, @Khurram hassan document.getElementById() . Chrome, null. , getElementsBy* getElementBy*. , , ClassName, Name TagNameNS , . , , TagNameNS, , .

, , <!DOCTYPE html> , , , . <!DOCTYPE html> , , ( ) HTML-. , ( , ), - .

0

Source: https://habr.com/ru/post/1729114/


All Articles