473,770 Members | 6,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[2].style.display= "none";
document.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[3].style.display= "none";
}
but it does not work.

If i write :
document.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[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 6967


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.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[2].style.display= "none";

document.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[3].style.display= "none";

}
but it does not work.

If i write :
document.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[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 getElementsByTa gName('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.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[2].style.display= "none";

document.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[3].style.display= "none";

}
but it does not work.

If i write :
document.getEle mentById(id_img ).parentNode.pa rentNode.childN odes[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
4802
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 links and i arrived to the conclusion that i can not access class Name with Mozilla. With Explorer i can acesss with document.all.className but i want visualize my web site in Opera 7.2, Mozilla 1.4 and Explorer 6.0. My code will be something like...
1
1211
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 users can acess this directory. How can i do to send my credentials, this way be able to save at the directory? Tks in adv.
0
1250
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 ---------------------------------------------------------------------------------------------------------- NOT WORK
2
1280
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(); where currentchildelem is an Element childNodesBuffer is a NodeList
4
2014
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 debug using my own debug statments. and PC's value is 0x00000 which is no way helpful for backtracking the problem. Sp please guide me .
0
1460
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 Kind regards Zar <ArrayOfPortalResult> <PortalResult> <PortalUser> <WindowsID>123</WindowsID> </PortalUser> <Completed>1</Completed>
0
2530
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 enviroment setup and Data source connection. Could anybody help me resolve the issue. Thank you very much for yout time. HTTP Status 500 -
2
1208
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 through every diagnostics they can do also and is not a connection problem, I have contacted my computer manufacturer and they have said its not my computer as they cannot access the site either, microsoft have suggested I try to get help here, I...
1
1907
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 not ( iam using vb2005 as front end and MS acess as by back end) Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the...
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10225
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.