If you want the ID of an element, you just ask for it. gh.id
–
squintJul 3 '12 at 12:36

Tried .innerHTML on the element? That should give you the text/html that is inside the <h2>-tag
–
NoLifeKingJul 3 '12 at 12:37

A few things to remember. First, if you're asking to get some value from an element, show the HTML markup in your question so it is clear what you're talking about. Second, HTML exists on the server. when you're in the DOM, you have objects that were created when the HTML was parsed. The only HTML in the DOM is that which is dynamically generated, and is usually not what you want.
–
squintJul 3 '12 at 12:47

I think OP wants the id of the element. Not the HTML content.
–
squintJul 3 '12 at 12:43

@amnotiam - "However, the ts variable is the ID or name of the Type of Element, not the Element's value itself"... to me that sounds like they want the "value" of the element. I assume that means the content.
–
James AllardiceJul 3 '12 at 12:45

Maybe you're right. I hate it when people don't describe and illustrate exactly what they want.
–
squintJul 3 '12 at 12:50

@amnotiam - Yeah... hard to tell what's actually being asked. I'll leave my answer as it is for now, unless the OP updates the question.
–
James AllardiceJul 3 '12 at 12:50

What I was asking for was the bit that would go inside two <h2></h2> tags
–
JamEngulfer221Jul 3 '12 at 13:00

It's safer to use gh.innerText as it would also return text including line breaks and images in-between. the first child node only contains the text up to the first non text node.
–
Torsten WalterJul 3 '12 at 13:15

@TorstenWalter I tried that, but when I made the variable pop up in an alert, it only displayed a blank window with an 'ok' button.
–
JamEngulfer221Jul 3 '12 at 14:40

If you want to access the type of an element you can just ask for this:

gh.nodeName // contains the name of the node in uppercase e.g. "H2"
gh.nodeType // contains the numerical Type of the node e.g. "1"
gh.id // contains the value of the node's id attribute
gh.name // contains the value of the name attribute (typically for form elements)

As mentioned below, accessing the actual node content is a different matter: