Javascript DOM HTML Node namespaceURI Property

Introduction

Get the URI of the namespace for an HTML document:

var x = document.documentElement.namespaceURI;

Click the button get the URI of the document's namespace.

View in separate window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<body>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {//from  w ww . j av a  2 s.co  m
  var x = document.documentElement.namespaceURI;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The namespaceURI property returns the URI of the specified node's namespace.

An element node inherits the namespace of its parent node, therefore, all elements in an XHTML document has the namespaceURI "http://www.w3.org/1999/xhtml".

This property is read-only.

The namespaceURI property returns null if the node is not in a namespace.




PreviousNext

Related