HTML DOM isDefaultNamespace( ) Method


The HTML DOM isDefaultNamespace() method returns a boolean value (true/false) if specified namespace is default or not.

Note − 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".

Syntax

Following is the syntax −

Calling isDefaultNamespace()

document.documentElement.isDefaultNamespace("nameSpaceURI")

Example

Let us see an example for isDefaultNamespace() method −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>isDefaultNamespace()</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>isDefaultNamespace( )</legend>
<label for="textSelect">URI:
<input type="url" size="25" id="textSelect" placeholder="http://www.abc.com">
</label><br>
<input type="button" onclick="confirmNameSpace()" value="Check">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputText = document.getElementById("textSelect");
   divDisplay.textContent = 'NOTE: Check if specified URI is DefaultNamespace';
   function confirmNameSpace() {
      if(document.documentElement.isDefaultNamespace(textSelect.value))
         divDisplay.textContent = 'Above given namespace is default';
      else
         divDisplay.textContent = 'Above given namespace is not default';
   }
</script>
</body>
</html>

Output

This will produce the following output −

Before clicking ‘Check’ button −

After clicking ‘Check’ button with invalid input −

After clicking ‘Check’ button with valid input −

Updated on: 30-Jul-2019

63 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements