You are here: Reference > JavaScript > client-side > xml handling > properties > localName (attribute, Element)
localName property (attribute, Element)
9 | ||||
Returns the local part of the qualified name of the current node.
To set or return the namespace URI and prefix of a node, use the namespaceURI and prefix properties.
In Internet Explorer, the baseName property provides the same functionality as the localName property in XML documents.
In HTML documents, the localName property retrieves the tag name of an element in uppercase in Opera and Firefox before version 3.6, and in lowercase in Firefox from version 3.6, Safari, Google Chrome and Internet Explorer from version 9. If you want to get the tag name of an HTML element, use the cross-browser nodeName and tagName properties instead.
In HTML documents, the localName property retrieves the tag name of an element in uppercase in Opera and Firefox before version 3.6, and in lowercase in Firefox from version 3.6, Safari, Google Chrome and Internet Explorer from version 9. If you want to get the tag name of an HTML element, use the cross-browser nodeName and tagName properties instead.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read-only.
Possible values:
String that represents the local name.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the localName and baseName properties:
|
|||||||
<head> <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var httpRequest = null; function SendRequest () { if (!httpRequest) { httpRequest = CreateHTTPRequestObject (); // defined in ajax.js } if (httpRequest) { // The requested file must be in the same domain that the page is served from. var url = "ns.xml"; httpRequest.open ("GET", url, true); // async httpRequest.onreadystatechange = OnStateChange; httpRequest.send (null); } } function OnStateChange () { if (httpRequest.readyState == 0 || httpRequest.readyState == 4) { if (IsRequestSuccessful (httpRequest)) { // defined in ajax.js GetTagInfo (); } else { alert ("Operation failed."); } } } function GetTagInfo () { var xmlDoc = ParseHTTPResponse (httpRequest); // defined in ajax.js if (!xmlDoc) return; if (xmlDoc.getElementsByTagNameNS) { // Firefox, Opera, Google Chrome and Safari var titleTags = xmlDoc.getElementsByTagNameNS ("http://help.dottoro.com/NS", "title"); if (titleTags.length > 0) { var message = "The localName of the first title tag: " + titleTags[0].localName + "\n" + "The namespaceURI of the first title tag: " + titleTags[0].namespaceURI + "\n" + "The prefix of the first title tag: " + titleTags[0].prefix; alert (message); } else { alert ("There is no title tag!"); } } else { // Internet Explorer var titleTags = xmlDoc.getElementsByTagName ("dotto:title"); if (titleTags.length > 0) { var message = "The localName of the first title tag: " + titleTags[0].baseName + "\n" + "The namespaceURI of the first title tag: " + titleTags[0].namespaceURI + "\n" + "The prefix of the first title tag: " + titleTags[0].prefix; alert (message); } else { alert ("There is no title tag!"); } } } </script> </head> <body> <button onclick="SendRequest ()">Get localName, namespaceURI and prefix</button> </body> |
|||||||
|
|||||||
Did you find this example helpful?
|
Supported by objects:
attribute
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments