Jump to content

w3c standard to substitute document.all


michbeta

Recommended Posts

Hi,I would like to browse all element of an html page.I found in internet this sample:--------------------------------<HTML><HEAD><TITLE>Elements: Collecting</TITLE><script LANGUAGE="JavaScript">function showElements() { var tag_names = ""; for (i=0; i<document.all.length; i++) tag_names = tag_names + document.all(i).tagName + " "; alert("This document contains: " + tag_names);}</SCRIPT></HEAD><BODY onload="showElements()"><H1>Welcome!</H1><P>This document is <B>very</B> short.</BODY></HTML>--------------------------------This is working but the Firefox Java Consoloe says that document.all is not Standard and suggests to use getElementById().But getElementById() needs an Id. Instead I would like to browse ALL elements of the page.How can I do it?Thanks,Michele

Link to comment
Share on other sites

Hi,I would like to browse all element of an html page.I found in internet this sample:This is working but the Firefox Java Consoloe says that document.all is not Standard and suggests to use getElementById().But getElementById() needs an Id. Instead I would like to browse ALL elements of the page.How can I do it?Thanks,Michele
Hi!DOM (document object model) is a W3C standard. microsoft.all is not within it. :)This wil get all tags from document to array with DOM:var tags = document.getElementsByTagName("*"); // star means "all"if You need only div -elements:var divs = document.getElementsByTagName("div");and then divs[2].style.color = "#FF0000";in this case third div of the document will get red color.Hope this help .. there is a lot more:http://www.w3schools.com/htmldom/dom_obj_document.asp
Link to comment
Share on other sites

Hi!DOM (document object model) is a W3C standard. microsoft.all is not within it. :)This wil get all tags from document to array with DOM:var tags = document.getElementsByTagName("*"); // star means "all"
Thanks Raimo,the statement you suggested is that I was lookig for.I didn't think to try with '*' before to read your answer.Michele
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...