Results 1 to 4 of 4

Thread: getElementById(activeSection).childNodes.item(0).nodeValue

  1. #1
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question getElementById(activeSection).childNodes.item(0).nodeValue

    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>
    <head>
    <title>Summary</title>
    </head>

    </html>


    </div>



    Thanks for your help.
    Last edited by fseguin; 11-24-2005 at 02:57 PM.

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by fseguin
    <div class='billSection' id='SectionD'><html>
    <head>
    <title>Summary</title>
    </head>

    </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.

    Mike

  3. #3
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Any suggestion for a work around.

    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?


    François

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,951
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    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?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •