Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    34
    Thanks
    6
    Thanked 0 Times in 0 Posts

    REALLY SIMPLE - return the node's text

    Code:
    <label for="_QsT_283$1_8">Don't know</label>
    I have the HTML above in a page and I'm trying to figure out how to return the text "Don't know". I have the correct object node for the <label> tag, and I've tried using:

    node.nodeValue;
    node.Text;

    and that returns null and undefined, respectively. What can I do to get that text from between the tags?

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts
    Possible node.innerHTML

  • Users who have thanked flynch01 for this post:

    brookey86 (04-29-2008)

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    725
    Thanks
    35
    Thanked 132 Times in 123 Posts
    <label for="_QsT_283$1_8">Don't know</label>
    The element node contains a childNode, which is the actual container of the text.
    If node refers to the label element you could use

    node.firstChild.nodeValue or
    node.childNodes[0].data


  •  

    Posting Permissions

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