views:

89

answers:

1

I want to get the name of a certain tag (to tell whether it is a div/input/span/p/so on)

I found that there are 3 different attributes that give me the tag name:

tagName, nodeName, and localName

My question is: Which one is the most supported in all browsers? And/or is there a method to get the tag name in Prototype (I looked but couldn't find one)?

+7  A: 

nodeName is the most consistent here. I would suggest you take a minute and read this post for a few differences and inconsistencies with tagName if you're more curious as to why.

For the prototype part of the question...it's a JavaScript property, just this.nodeName should work or element.nodeName, whatever your element's called in the current function should work.

Nick Craver
Nice link to the article, +1 :). As for the prototype function, I just meant is there a function that determines which property is best to use based on the browser, like using `update()` instead of `.innerHTML`
webdestroya
@webdestroya - Since this one works consistently across browsers, no need to add any overhead in the library, for example jQuery doesn't have any method for this either :)
Nick Craver
Ah good point. Thanks for the answer!
webdestroya