This method is used to insert a string at the specified offset.
The insertData method is used to insert a string at the specified offset. The data and length properties are both immediately updated by this operation.
XML:
<Albums>
<Album ref="CD142" category="Folk">
<title>Boil The Breakfast Early</title>
<artist>The Chieftains</artist>
</Album>
<Album ref="CD720" category="Pop">
<title>Come On Over</title>
<artist>Shania Twain</artist>
</Album>
<Album ref="CD024" category="Country">
<title>Red Dirt Girl</title>
<artist>Emmylou Harris</artist>
</Album>
</Albums>
JavaScript:
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("albums.xml");
elem = xml_doc.documentElement.firstChild;
text = elem.lastChild.firstChild;
text.insertData(4, "One And Only ");
document.write(text.data);
document.write("<br>The length of the string is now " + text.length);
The One And Only Chieftains
The length of the string is now 27
In this example we use the 'albums.xml' file and insert the string 'One And Only ' after the word 'The' in the 'artist' element of the first 'album'. Then we display the new string and its length.