tagName (W3C DOM Core property)
| Version | Depr. | Static | Read-only |
|---|---|---|---|
| DOM1 | No | No | Yes |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
Example
var tag = element.tagName;
The
example above saves a reference to the tagName of
an element, so if the element reference pointed to an
HTML blockquote element:
<blockquote> <p>I found some kinda fairytale</p> </blockquote>
Then the tag variable
would have the value BLOCKQUOTE.
Description
The qualified name of an Element node, including any namespace prefix.
In HTML this is returned in all uppercase regardless of the case used in the document; in XML the case used in the document is preserved.
In all cases, the tagName of an element is exactly the same as its nodeName.
This property is readonly.
Since the case of the returned value depends on whether the
document is HTML or XML (which includes XHTML mode1), it's often
helpful to run this value through JavaScript's
toLowerCase function, to get a value with
predictable case:
var tag = element.tagName.toLowerCase();
The tag variable would then have the value
blockquote, regardless of the document type.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.