tags:

views:

2387

answers:

2

I feel like this should be really easy to do, but I'm stumped. I need a way for Javascript to determine the type of an HTML element. It has the id, but the element itself could be a div, a form field, a fieldset, etc. Can anyone tell me how to do this?

+6  A: 

What about element.tagName?

Brian Cline
According to timestamps you beat me by less than 1 second!
eyelidlessness
I even managed to throw in some extraneous english. Crikey!
Brian Cline
From QuirksMode: My advice is not to use tagName at all.nodeName contains all functionalities of tagName, plus a few more. Therefore nodeName is always the better choice.
bdukes
+6  A: 

I think nodeName is the attribute you are looking for. For example:

var elt = document.getElemementById('foo');
alert(elt.nodeName);
pkaeding