michbeta Posted April 3, 2006 Share Posted April 3, 2006 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 More sharing options...
raimo Posted April 3, 2006 Share Posted April 3, 2006 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,MicheleHi!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 More sharing options...
michbeta Posted April 7, 2006 Author Share Posted April 7, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now