How to use DOM Object CreateCDATASelection in JavaScript

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

JavaScript Window object CDATASelection() Method

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


xmlData.CreateCDATASelection("Some text")




    <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"); }


  "GET", "abc.xml", false);


            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");


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

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

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

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





    <button onclick="myfun()">

        click me</button>


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







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


More Articles

© 2020 DotNetHeaven. All rights reserved.