You are here: Reference > JavaScript > client-side > xml handling > properties > dataType (attribute, Element)

dataType property (attribute, Element)

Browser support:
Sets or returns the data type for the current element or attribute.
This property has an effect on the nodeTypedValue property, it sets or retrieves the value of a node in the data type defined by the dataType property.

Syntax:

object.dataType;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that sets or returns the data type, or null if the data type is not declared, or invalid.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the dataType property:
Code
ajax.js
<head>
    <script type="text/javascript" src="ajax.js"></script>
    
    <script type="text/javascript">
        function TestDataTypesAndValues () {
                // create an XML document
            var xmlDoc = CreateXMLDocumentObject ("root");  // defined in ajax.js
            if (!xmlDoc) {
                return null;
            }

            var root = xmlDoc.documentElement;

                // add two elements to the document with different data types
            var sizeNode = xmlDoc.createElement ("size");
            sizeNode.dataType = "int";
            sizeNode.nodeTypedValue = 120;
            root.appendChild (sizeNode);

            var colorNode = xmlDoc.createElement ("color");
            colorNode.dataType = "string";
            colorNode.nodeTypedValue = "red";
            root.appendChild (colorNode);

                // get the data type and value of the elements
            var sizeNode = root.getElementsByTagName ("size")[0];
            alert ("The data type and value of the size element:\n" + 
                    sizeNode.dataType + ", " + sizeNode.nodeTypedValue);

            var colorNode = root.getElementsByTagName ("color")[0];
            alert ("The data type and value of the color element:\n" + 
                    colorNode.dataType + ", " + colorNode.nodeTypedValue);

                // display the source of the XML
            alert ("The source of the XML:\n" + root.xml);
        }
    </script>
</head>
<body>
    <button onclick="TestDataTypesAndValues ();">Test data types and values</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content