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 to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool how to access value in DIV tag

    Hi everyone,

    i am new to JavaScript, i am writing this js to get a value from the div tag but

    the DOM inspector shows tree like

    Code:
    -DIV   (id=p1)
     -DIV    (id=p2)
      -NAME
       #text        (<-- this is the value that i want to retrieve)
    if i try
    Code:
    document.getElementById(p1).lastChild
    it returns [object HTMLDivElement]

    any idea what i am doing wrong?

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Hi,

    You need to grab the value, try:
    document.getElementById("p1").lastChild.nodeValue

    Good luck;

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    solved!

    Code:
    var abc = document.getElementsByTagName("name");
    var value_to_store = abc[0].firstChild.nodeValue;
    thanks


  •  

    Posting Permissions

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