XML DOM deleteData() Method

Definition and Usage

deleteData() The method removes data from the text node.

Syntax

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

Example

The following code loads "books.xml" into xmlDoc and removes some characters from the text node of the first <title> element:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0].childNodes[0];
    document.getElementById("demo").innerHTML =
    x.nodeValue;
    x.deleteData(0, 9);
    document.getElementById("demo").innerHTML +=
    "<br>" + x.nodeValue;
}

Try It Yourself