View Full Version : getElementById(activeSection).childNodes.item(0).nodeValue

11-24-2005, 03:53 PM
I'm trying to extract some information from the various DIV to include a title in the document.title.

The code is a legacy code for which for the purpose of this test I have simplified. This legacy code is replicated in hundreds of HTMLs. For this reason, I'm trying to extract the information from the various DIV with some DHTML instructions without success.

The DIV has an ID for which I can reference no problem. The info I would like to extract is found inside this DIV and I would assume is called a child of this DIV. When I display the length of this childNodes it returns 0 when I do expect it to have childs.

Each Div has a <title> tag. This is the info I would like to extract.

Here's the code in question:

alert("length = " + document.getElementById("SectionD").childNodes.length);
alert("Value = " + document.getElementById("SectionD").childNodes.item(0).nodeValue);


The Div in Question:

<!-- section divider -->
<div class='billSection' id='SectionD'><html>



Thanks for your help.

11-24-2005, 05:59 PM
<div class='billSection' id='SectionD'><html>


</div>There's no way you can expect to walk the document tree with such poor markup.

The DOM should be used with valid markup. Documents that are invalid are liable to be error corrected, and there's no way to accurately predict how the resulting tree will be structured.


11-24-2005, 07:13 PM
Hi Mike:

thanks for your comments for which I totally agree with. Though, I was looking for help and a suggestion on how to avoid rewriting all the DHTML's. As I mentioned, there are hundreds for which I inherited to extract information from.

The coding may be somewhat off but nevertheless works as the browsers are simply ignoring the extra parts.

What they ignored I would like to capture.

So, would you have a constructive suggestion or is there really no way out but to recode all the DHTMLs?

I was thinking in the lines of some JavaScript with DOM object to read the DHTML we are in as a text file without any interpretation in order to do a search in it and extract the desired text.

Let me know if you know of any way around?


11-25-2005, 01:57 AM
Well, ever willing to jump in 'where angels fear to tread', I would say that even if that markup could be considered for evaluation of the nodeValues of its nodes contained in that division, that is to say if that didn't freak out the browser, all nodeValues of those tags would be 'null' and some, or all of the line breaks would be considered nodes too (depending upon the browser) each with a nodeValue of hex 0a. What information are you trying to extract? Since you have the id of the containing element, why not query it's innerHTML and see if that gives you anything to work with?