开发者

What is the best way to get an element's tag name in JS?

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 ta开发者_如何学JAVAg name in Prototype (I looked but couldn't find one)?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜