How to get the value of an id

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • El Milahi
    New Member
    • Mar 2008
    • 2

    #1

    How to get the value of an id

    I'm trying to get the value of an id. This is my code:

    <span id="test">this value</span>
    <script type="text/javascript">
    var myVal = document.getEle mentById('test' ).value;
    alert(myVal);
    </script>

    When I run it I get "undefined" in the alert window.
    How can I get the value "this value" from the span?

    Please help.
  • El Milahi
    New Member
    • Mar 2008
    • 2

    #2
    I found it.
    I should use document.getEle mentById('test' ).innerHTML;

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Originally posted by El Milahi
      I found it.
      I should use document.getEle mentById('test' ).innerHTML;
      I will move this over to the Javascript forum for further input by the users there, but next time, please post technical questions in their appropriate technical forum.

      Regards,

      Moderator

      Comment

      Working...