views:

88

answers:

1

Using document.GetElementById(thingieID) doesn't seem to work. Can anyone help this DOM newbie?

A: 

I'm not sure what you are trying to do with the element, or what the problem is.

Here's an example of using document.GetElementById() in a webpage, in a function that is invoked on the onClick event for a button.

<html>
  <head>
    <title>Example of GetElementById</title>
  </head>
  <body>
    <p id="hello">Hello World</p>
    <input type="button" value="Update" onclick="btn1_Click();"/>
    <script type="text/javascript">
      // <![CDATA[
      function btn1_Click()
      {
          if (document.getElementById('hello')) {
              document.getElementById('hello').innerHTML = 'Hello World - this was inserted using JavaScript at ' + new Date().toString();
          }
      }
    // ]]>
    </script>
  </body>
</html>

You can see this run at:
http://jsbin.com/afaga/2

Cheeso
thanks for answer - at the risk of exposing my ignorance, what i really need is a handle to the object within Javascript - assumed this was the XPATH, but maybe nothere's an example: this "node" or element or whatever is within a table/tbody/tr:<th align="left" id="GridHeaderCol4" style="padding-bottom: 2px; padding-left: 2px; width: 70px; padding-right: 2px; cursor: hand; padding-top: 2px;" onmouseover="this.style.backgroundImage='url....>using document.GetElementById('GridHeaderCol4') doesn't work - no objectso using IE only (not Firefox), i need to get a handle to the object
Jon Lawrence
it's not XPath. An Element ID is not xpath. Maybe you could reframe your question, provide a very simple .htm document that shows the problem you're having.
Cheeso
ok, I'm going to update my answer and your question.
Cheeso
The problem is just in capitalization?
Working, capitalization may have been the problem. IE8 Dev Tools (F12) using Find=>Select By Click is useful, then View=>Source=>DOM Element, and construct the Element ID from the XML tree. Thanks for everyone's input. This site comes up a lot in my Google searches, and it seems like a useful resource :-)
Jon Lawrence