JavaScript - createCDATASection() method

revision:


Category : document

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

Note: createCDATASection is intended for XML and will not work for HTML documents.

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