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)?
The tagName read-only property of the Element interface returns the tag name of the element on which it's called. For example, if the element is an <img> , its tagName property is "IMG" (for HTML documents; it may be cased differently for XML/XHTML documents).
Definition and Usage. The tagName property returns the tag name of an element. The tagName property returns the tag name in UPPERCASE.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With