Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting child nodes 1

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hey all I have yet another question for ya'all:
Code:
<div id="rOne">
			<div class="c1">Jojn</div>
			<div class="c2">Ra-Ray</div>
			<div class="c3">555-555-6598</div>
</div>
I want to get access to all the divs under the rOne div, can I do this. I was trying to do this with this command,
Code:
 var p = document.getElementById('rOne').childNodes;
but I am getting errors that document.getElementById('rOne').childNodes has no properties. What am I doint wrong.

again,
Thanks for the help.
-T


-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
In terms of your code, you are doing nothing wrong.

My guess is that you are trying to get the childNodes before the object exists.

Quick example:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/frameset.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function refreshParent() {
  var p = document.getElementById("rOne").childNodes;
  alert(p.length);
}   
</script>
</head>
<body>
<input type="button" onclick="refreshParent()" />
<div id="rOne">
            <div class="c1">Jojn</div>
            <div class="c2">Ra-Ray</div>
            <div class="c3">555-555-6598</div>
</div>

</body>
</html>

This works because the divs exist when we call the function

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/frameset.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
  var p = document.getElementById("rOne").childNodes;
  alert(p.length);
</script>
</head>
<body>
<div id="rOne">
            <div class="c1">Jojn</div>
            <div class="c2">Ra-Ray</div>
            <div class="c3">555-555-6598</div>
</div>

</body>
</html>

This will not work because it tries to get the child nodes as the page is loading and before the divs exist.

[monkey][snake] <.
 
Man .. again I owe you one, let me know where to send the beer :)

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Sorry dude I thought that I did that already, u da man... or woman

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top