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
2010-01-21 21:19:51
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
2010-01-21 21:36:51
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
2010-01-21 21:48:03
ok, I'm going to update my answer and your question.
Cheeso
2010-01-22 01:25:05
The problem is just in capitalization?
2010-01-23 00:15:00
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
2010-01-23 21:13:31