XML DOM prefix Property
Node Object
Example
The following code fragment loads "books_ns.xml" into xmlDoc and returns the namespace prefix of the <title> elements:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
��� if (xhttp.readyState == 4 && xhttp.status == 200) {
������� myFunction(xhttp);
��� }
};
xhttp.open("GET",
"books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
var x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName("title");
for (i = 0; i <
x.length; i++) {
txt +=
"Prefix: " + x.item(i).prefix + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
Output:
Prefix: c
Prefix: x
Try it yourself »
Definition and Usage
The prefix property sets or returns the namespace prefix of a node.
Browser Support
The prefix property is supported in all major browsers.
Syntax
Set the namespace prefix:
nodeObject.prefix=prefix
Return the namespace prefix:
nodeObject.prefix
Technical Details
Return Value: | A String representing the namespace prefix of the node, or null if the node does not have a namespace |
---|---|
DOM Version | Core Level 2 Node Object |
Node Object