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?
According to timestamps you beat me by less than 1 second!
eyelidlessness
2008-10-31 17:32:56
I even managed to throw in some extraneous english. Crikey!
Brian Cline
2008-10-31 17:34:04
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
2008-10-31 17:38:14
+6
A:
I think nodeName
is the attribute you are looking for. For example:
var elt = document.getElemementById('foo');
alert(elt.nodeName);
pkaeding
2008-10-31 17:33:45