JavaScript - createCDATASection() method

revision:


Category : document

createCDATASection() creates a new CDATA section node, and returns it.

Syntax :

        createCDATASection(data)
    

Parameters:

data : a string containing the data to be added to the CDATA Section.

Examples:

            const docu = new DOMParser().parseFromString("<xml></xml>", "application/xml");
            const cdata = docu.createCDATASection("Some <CDATA> data & then some");
            docu.querySelector("xml").appendChild(cdata);
            console.log(new XMLSerializer().serializeToString(docu));
            // Displays: *lt;xml> data & then some]]></xml>
        

Practical examples

example: create CDATAsection()
code:
                    
                

example:
code:
                    
                

example:

example:

code: