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.
Last edited by fseguin; 11-24-2005 at 02:57 PM.
There's no way you can expect to walk the document tree with such poor markup.
Originally Posted by fseguin
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.
Any suggestion for a work around.
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?
Let me know if you know of any way around?
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?