insertData (W3C DOM Core method)

Version Depr. Static
DOM1 No No
Browser support (more…)
IE6+ FF1.5+ SA1.3+ OP9+
Full Full Full Full


var sentence = document.createTextNode
  ("When you're smiling, the whole world smiles with you.");

sentence.insertData(21, "yes when you're smiling, ");

In the example above we create a Text node with the value When you're smiling, the whole world smiles with you., then we use the insertData method to insert the string yes when you're smiling, at character offset 21.

The final result is a single Text node with the data (and nodeValue) When you're smiling, yes when you're smiling, the whole world smiles with you., that has a length of 78.


offset (unsigned long) required

The character offset at which to insert.

string (DOMString) required

The string to insert.


Insert a string into this character data at a specified character offset.

After a successful operation, the data and length properties of the node reflect the change.

Tip: JavaScript has more powerful native features

I've never used this method — JavaScript's built-in string manipulation methods are far more flexible and powerful than anything offered by the DOM.


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Partial Full Full Full Full Full Full Full Full Full Full

Internet Explorer 5.5 in HTML doesn't implement this method (it returns undefined).

User-contributed notes

There are no comments yet.

Related Products