How to use DOM Object CreateCDATASelection in JavaScript

In this article I am going to explain about DOM object CreateCDATASelection() Method in JavaScript.
  • 1204

JavaScript Window object CDATASelection() Method

JavaScript CDATASelection() Method use for create CDATASelection node for given specifics text.

Syntax

xmlData.CreateCDATASelection("Some text")

Example

<html>

<head>

    <p id="dmd">

        Click button for create CDATASelectio</p>

    <script type="text/javascript">

        function myfun() {

            var http;

            if (window.XMLHttpRequest) { VHF = new XMLHttpRequest(); }

            else { VHF = new ActiveXObject("Microsoft.XMLHTTP"); }

 

            VHF.open("GET", "abc.xml", false);

            VHF.send();

            var xmlDoc = VHF.responseXML;

            var cost = xmlDoc.getElementsByTagName("Cost")[0];

            var txt = "Before adding the CDATASection<br>";

            txt = txt + cost.childNodes[0].nodeValue;

            var cdat = xmlDoc.createCDATASection(" 55.90");

            cost.appendChild(cdat);

            txt = txt + "<br>After Adding CDATASelection<br>"

            txt = txt + cost.childNodes[0].nodeValue;

            txt = txt + cost.childNodes[1].nodeValue;

            document.getElementById("dmd").innerHTML = txt;

        };

    </script>

</head>

<body>

    <button onclick="myfun()">

        click me</button>

    <p>

        CDATASelection only work for xml and its not work in html</p>

</body>

</html>

 

Output


CDATA.gif

 

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.