www.webdeveloper.com
Results 1 to 5 of 5

Thread: capturing/changing child node

  1. #1
    Join Date
    Aug 2005
    Posts
    243

    capturing/changing child node

    this isn't working, but i'm not understanding why...i want to change the contents of the <span> within the <p> tag...all i have to work with is the <p> tag's ID.

    Code:
    document.getElementById('testid').childNodes[0].innerHTML='working!';
    and here's the html...

    Code:
    <p id="testid">this is <span>not working.</span></p>
    any hints?

  2. #2
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    The span isn't the first child node. It's the second.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  3. #3
    Join Date
    Aug 2005
    Posts
    243
    really? ok, now i'm confused...isn't it supposed to be in relation to the <p> and by being within the <p> it's a child of it correct? Sorry, guess it needs to be dumbed down for me

  4. #4
    Join Date
    Jul 2005
    Location
    USA
    Posts
    3,910
    Yes, the <span> is a child of the <p>. The childNodes[] collection includes more than just element nodes. It also includes text and comment (<!-- ... -->) nodes, for example, if any are present.

    You could use this instead of childNodes[]
    Code:
    document.getElementById('testid').getElementsByTagName('span')[0]
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

    Check out my blog.

  5. #5
    Join Date
    Aug 2005
    Posts
    243
    ok, cool...that makes more sense. thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles