Monday, May 13, 2024
16
rated 0 times [  23] [ 7]  / answers: 1 / hits: 25508  / 15 Years ago, tue, january 19, 2010, 12:00:00

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?


More From » google-chrome

 Answers
39

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 <!DOCTYPE> Tag is removed from your page, as well as the xmlns attribute is also removed from your <html> tag.



Change anything like this:



<!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>


to:



<html>


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



The reason: When you use the <!DOCTYPE> 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 <!DOCTYPE> tag otherwise document.all won't work.


[#97796] Friday, January 15, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinisaaka

Total Points: 194
Total Questions: 105
Total Answers: 104

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;