localName (W3C DOM Core property)
| Version | Depr. | Static | Read-only |
|---|---|---|---|
| DOM2 | No | No | Yes |
| IE7 | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| None | Full | Buggy | Full |
Example
var local = node.localName;
In the example above, if node is an
h1 element then the local variable
will have the value "h1"; if node is
an xml:id attribute1 then local will have
the value id; if it isn't an element or attribute then
local will be null.
In HTML, element names are returned in all uppercase, and attribute names in all lowercase, regardless of the case used in the document; in XML the case used in the document is preserved.
Description
The local name (ie. not
including any namespace prefix) of a Element or
Attr node; for other nodes this property is
null.
DOM 1 methods such as getAttribute are not namespace aware, and
identify nodes by their nodeName. Namespace aware DOM
2 methods such as getAttributeNS identify
nodes by a combination of their namespaceURI and localName; the localName and prefix combined form a qualified name
— a name which comprises the namespace prefix then the local name,
delimited with a colon.
This property is readonly.
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 |
| None | None | None | Full | Full | Full | Buggy | Buggy | Buggy | Full | Full |
In
Safari 1.3 and 2 this property returns
null; except for Element nodes
in XML, and created Element nodes in XHTML
mode2.
In
Safari 3 this property returns the nodeName of some nodes that aren't elements or attributes;
for example, it returns #text as the localName of a Text node, rather than
null.
Internet Explorer does not implement this property, and will return undefined.
Since localName is primarily an XML construct,
it's only reasonable to judge its behavior in terms of XML (either on
HTML pages in XHTML mode, or pure XML). The behavioral variations of
browsers in HTML mode3 are documented here for interest
and reference, but the support summary table above does not consider
this behavior (ie. if the property is fully supported in XML then it's
considered to be fully supported, with no notes).
In Opera,
Firefox and Safari
3 in HTML mode, the localName
property returns a qualified name, ie. the
value includes any namespace prefix and is the
same is its nodeName.
Footnotes
1 The W3C has published a
recommendation for an XML attribute called xml:id,
which is universally of type ID, and therefore if used
would remove the need for implementations to perform validation, or rely
on resource lookups or internal subsets. However only Opera 9 currently
implements this attribute.
2 On XHTML pages served as
application/xhtml+xml.
3 On XHTML or HTML pages served as
text/html.
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.




