You are here: Reference > JavaScript > client-side > xml handling > methods > isDefaultNamespace

isDefaultNamespace method

Browser support:
9
Returns whether the specified namespace URI is the default namespace in the scope of the current node.
Note: The isDefaultNamespace method of HTML elements and attributes is only supported in Firefox, Safari, Google Chrome and Internet Explorer from version 9. The default namespace for HTML elements and attributes is an empty string in Firefox, and "http://www.w3.org/1999/xhtml" in Google Chrome, Safari and Internet Explorer. In Opera, the isDefaultNamespace method always returns false on HTML elements and attributes.
Note: The isDefaultNamespace method is not supported in Internet Explorer in XML documents.
To get the namespace prefix that is associated with a namespace URI, use the lookupPrefix method. To get the namespace URI that is associated with a namespace prefix, use the lookupNamespaceURI method.

Syntax:

object.isDefaultNamespace (namespaceURI);
You can find the related objects in the Supported by objects section below.

Parameters:

namespaceURI
Required. String that specifies the namespace URI to test.

Return value:

Boolean. One of the following values:
false The specified namespace URI is not the default namespace.
true The specified namespace URI is the default namespace.

Example HTML code 1:

This example illustrates the use of the isDefaultNamespace method:
Code
ajax.js
ns.xml
<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
                    TestDefaultNamespace ();
                }
                else {
                    alert ("Operation failed.");
                }
            }
        }

        function TestDefaultNamespace () {
            var xmlDoc = ParseHTTPResponse (httpRequest);   // defined in ajax.js
            if (!xmlDoc)
                return;
                
            var firstItem = xmlDoc.getElementsByTagName ("item")[0];
            if (firstItem.isDefaultNamespace) {
                var isDef = firstItem.isDefaultNamespace ("http://help.dottoro.com/defaultNS");
                alert ("Is the 'http://help.dottoro.com/defaultNS namespace the default?\n" + isDef);
                var isDef = firstItem.isDefaultNamespace ("http://help.dottoro.com/NS");
                alert ("Is the 'http://help.dottoro.com/NS' namespace the default?\n" + isDef);
            }
            else {
                alert ("Your browser doesn't support the isDefaultNamespace method.");
            }
        }
    </script>
</head>
<body>
    <button onclick="SendRequest ()">Test the default namespace</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content