Problem Accesing all the Elements of the document

S

srinivas.aki

Hello Guys
This is the small script I have.
<!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">
<head>
<title>News Maps</title>
<script type="text/javascript">
function getTags()
{
if(!document.all)
document.all = document.getElementsByTagName("*");

for(var i=0;i<document.all.length;i++)
{
document.write(document.all.tagName)
}
}
</script>
</head>

<body>
<div id='feedOutput'>
<br />
</div>

<form name="FeedForm" id="feedForm" method="GET" action="#">
<input type="text" width="1000" name="feedURL"
value="http://localhost/map.xml" size="50" />
<input type="button" value="Syndicate" onclick="getTags();" />
</form>

</body>
</html>



The above function is printing out only the html, head, body tags but
not <div> I was not sure why that happening. Any ideas why ??

Thanks in advance
saki
 
D

Dominic Myers

Hello Guys
This is the small script I have.
<!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">
<head>
<title>News Maps</title>
<script type="text/javascript">
function getTags()
{
if(!document.all)
document.all =
document.getElementsByTagName("*");

for(var i=0;i<document.all.length;i++)
{
document.write(document.all.tagName)
}
}
</script>
</head>

<body>
<div id='feedOutput'>
<br />
</div>

<form name="FeedForm" id="feedForm" method="GET"
action="#">
<input type="text" width="1000" name="feedURL"
value="http://localhost/map.xml" size="50" />
<input type="button" value="Syndicate"
onclick="getTags();" />
</form>

</body>
</html>



The above function is printing out only the
html, head, body tags but
not <div> I was not sure why that happening. Any
ideas why ??

Thanks in advance
saki


Might this help
http://www.siteexperts.com/tips/contents/ts16/page3.asp?
Cheers, Dom
 
D

Dominic Myers

Hello Guys
This is the small script I have.
<!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">
<head>
<title>News Maps</title>
<script type="text/javascript">
function getTags()
{
if(!document.all)
document.all =
document.getElementsByTagName("*");

for(var i=0;i<document.all.length;i++)
{
document.write(document.all.tagName)
}
}
</script>
</head>

<body>
<div id='feedOutput'>
<br />
</div>

<form name="FeedForm" id="feedForm" method="GET"
action="#">
<input type="text" width="1000" name="feedURL"
value="http://localhost/map.xml" size="50" />
<input type="button" value="Syndicate"
onclick="getTags();" />
</form>

</body>
</html>



The above function is printing out only the
html, head, body tags but
not <div> I was not sure why that happening. Any
ideas why ??

Thanks in advance
saki


Further: Causes issues in IE, puts FireFox into an
infinite loop, as far as I can tell, but works a
treat in Opera... go figure.
 
L

Lasse Reichstein Nielsen

function getTags()
{
if(!document.all)
document.all = document.getElementsByTagName("*");

Remember that document.all is a dynamic collection that changes
when the page changes, whereas the element list returned by gEBTN
is not.
for(var i=0;i<document.all.length;i++)
{
document.write(document.all.tagName)


When you do a document.write after a page has loaded, the entire
document is replaced with a new one where the content is written.
If document.all is the dynamic collection, clearing the document
might cause problems.

Instead, you could put the elements into an array and then do
one single document.write (or put it into a text area instead
to completely avoid changing the document structure).

The above function is printing out only the html, head, body tags but
not <div> I was not sure why that happening. Any ideas why ??

Not sure why those excact symptoms occur, but I'm not surprised that
something odd happens :)
/L
 
R

Richard Cornford

Lasse said:
Remember that document.all is a dynamic collection that
changes when the page changes, whereas the element list
returned by gEBTN is not.
<snip>

This is not necessarily true. The gEBTN method is specified as returning
a - NodeList - and "NodeList objects in the DOM are live." So the
resulting object should be dynamic.

Richard.
 
R

Richard Cornford

Danny said:
I don't think you can wildcard the argument,
<snip>

Without a context for your reply the immediate question is "what
argument?". But assuming you are referring to the -
getElementsByTagName - call in the post to which you are responding, you
might consider reading the W3C Core DOM level 2 specification (where -
getElementByTagName - is defined), and save yourself looking more inept
than your failure to produce well-formed newsgroup posts already
suggests.

Richard.
 
L

Lasse Reichstein Nielsen

Richard Cornford said:
This is not necessarily true. The gEBTN method is specified as returning
a - NodeList - and "NodeList objects in the DOM are live." So the
resulting object should be dynamic.

I stand corrected. And it *is* dynamic in the first three browsers I
checked (Opera 8.5, IE 6 and Firefox 1.0.5).

/L
 
S

srinivas.aki

Lasse,
Thanks for the input. I got rid off all the document.writes and
replaced them with alerts, It worked smooth. You seem to be right about
how document.write updates the elementslist. Its working now.

Thanks
saki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top