XML DOM deleteData() Method

Definition and Usage

deleteData() The method deletes data from a CDATA node.

Syntax

CDATANode.deleteData(start,length)
Parameter Description
start Required. Specifies the position from which characters should be removed. The starting value is zero.
length Required. Specifies the number of characters to be removed.

Example

The following code loads "books_cdata.xml" into xmlDoc and removes some characters from the text node of the first <html> element (the "<b>" tag):

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   {}
};
xhttp.open("GET", "books_cdata.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("html")[0].childNodes[0];
    x.deleteData(0, 3);
    document.getElementById("demo").innerHTML =
    x.data;
{}

Try It Yourself