473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

childnode acess problem?

Hi,
I have a structure like this in my xhtml 1.0 file.
<body>
<div>
<a>
<img ... id="f1" />
<span>....</span><br/>
<span>....</span>
</a>
---> <div>
<img />
<span>....</span><br/>
<span>....</span>
</div>
---> <div>
<img />
<span>....</span><br/>
<span>....</span>
</div>
</div>
</body>

I want to acces the div blocks with the arrows from a java script. I use
the javas script object reference elment node. When somebody clicks on
the image with id f1, i want to make invisible the div elements with arrows.
I try to write this:

function make_visible(id_img){
document.getElementById(id_img).parentNode.parentN ode.childNodes[2].style.display="none";
document.getElementById(id_img).parentNode.parentN ode.childNodes[3].style.display="none";
}
but it does not work.

If i write :
document.getElementById(id_img).parentNode.parentN ode.childNodes[1].style.display="none";
after clicking the <a> block gets invisible. The next child will be the
div element. Isn't it?
I do not understand why it does not work, can anybody help me?

Jul 20 '05 #1
2 6947


Sergio del Amo Caballero wrote:
I have a structure like this in my xhtml 1.0 file.
<body>
<div>
<a>
<img ... id="f1" />
<span>....</span><br/>
<span>....</span>
</a>
---> <div>
<img />
<span>....</span><br/>
<span>....</span>
</div>
---> <div>
<img />
<span>....</span><br/>
<span>....</span>
</div>
</div>
</body>

I want to acces the div blocks with the arrows from a java script. I use
the javas script object reference elment node. When somebody clicks on
the image with id f1, i want to make invisible the div elements with
arrows.
I try to write this:

function make_visible(id_img){
document.getElementById(id_img).parentNode.parentN ode.childNodes[2].style.display="none";

document.getElementById(id_img).parentNode.parentN ode.childNodes[3].style.display="none";

}
but it does not work.

If i write :
document.getElementById(id_img).parentNode.parentN ode.childNodes[1].style.display="none";

after clicking the <a> block gets invisible. The next child will be the
div element. Isn't it?
I do not understand why it does not work, can anybody help me?


Don't rely on childNodes[index] to be an element node, in Mozilla's DOM
and in Opera 7's DOM the white space text nodes between element nodes
are modelled in the DOM while they are not in IE/Win therefore cross
browser code using childNodes[index] to expect a certain element doesn't
work. Instead use getElementsByTagName('tagname') and index that
collection, as long as you aware of nested elements appearing in there
too your code will work cross browser.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
DU
Sergio del Amo Caballero wrote:
Hi,
I have a structure like this in my xhtml 1.0 file.
<body>
<div>
<a>
<img ... id="f1" />
<span>....</span><br/>
<span>....</span>
</a>
---> <div>
<img />
<span>....</span><br/>
<span>....</span>
</div>
---> <div>
<img />
<span>....</span><br/>
<span>....</span>
</div>
</div>
</body>

I want to acces the div blocks with the arrows from a java script. I use
the javas script object reference elment node. When somebody clicks on
the image with id f1, i want to make invisible the div elements with
arrows.
I try to write this:

function make_visible(id_img){
document.getElementById(id_img).parentNode.parentN ode.childNodes[2].style.display="none";

document.getElementById(id_img).parentNode.parentN ode.childNodes[3].style.display="none";

}
but it does not work.

If i write :
document.getElementById(id_img).parentNode.parentN ode.childNodes[1].style.display="none";

after clicking the <a> block gets invisible. The next child will be the
div element. Isn't it?
I do not understand why it does not work, can anybody help me?


I'm just adding a few notes to what Martin replied to you.

Whitespace in the DOM:
"The presence of whitespace in the DOM can make manipulation of the
content tree difficult in unforseen ways. In Mozilla, all whitespace in
the text content of the original document is represented in the DOM (...)"
http://www.mozilla.org/docs/dom/technote/whitespace/

There are a number of ways to work around this Mozilla difficulty.
One would be to access the targeted node in a different manner. Here,
your instruction needs to travel 4 different node in the document tree.
So, even if the white space issue was not a problem, the code needed
would still involve a rather long DOM-Tree path. I personally would
examine this issue.
Second alternative would be to remove all white spaces involved. The
code used would work without adjustement for Mozilla-based browsers.
Also, removing white spaces makes the source document a bit faster to
parse and to render.
DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sergio del Amo Caballero | last post by:
I want to access div elemnent and make them visible or invisible with a condition. They belong to a particular class or not. I was reading the newsgroup old posting about classname acess and some...
1
by: Fabiano | last post by:
Please, i created a webpage that let's user upload a file to server. At my codebehind i need to save this file into a directory of another server (webfarm). The olny problem is that only some...
0
by: minhadd | last post by:
Hello Would Anyone help me ?? I want insert into Microsoft Acess visitor's IP by ASP. But It is not working ...
2
by: anupamjain | last post by:
I have gone through many threads on this topic, but am still clueless about the solution of my problem. I am using : childNodesBuffer = currentchildelem.cloneNode(true).getChildNodes(); ...
4
by: gogo | last post by:
my C program crashes due to segfault . And on using gdb it shows message "can not acess memory at address ox0" what could be the possible problem. Program is vary complecated so i can not simple...
0
by: Zarwadi | last post by:
Hi I've got this XML data. And when I call it into flash I can see it but I can not work out how the childNode work. I did not write the XML and the person how did is not around can anyone help me...
0
by: giridharpolaki | last post by:
I am getting the error below mentioned while I am trying to acess msaccess data base from apache , I have cross checked the program , its entirely perfect, I think there should be some problem with...
2
by: =?Utf-8?B?bWFycmNoaWU=?= | last post by:
Hi ther can anyone help me, I was able to acess my employers website, up until a few days ago, I have all the help from theit it support they can give me, they say its my provider, but I have been...
1
by: lokeshreddy16 | last post by:
'this is my code plz guys help how to save data from vb 2005 and other this that i am able to view the data from acess but i am not able save to acess i dont whether my code for save is correct of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.