deleteData (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM1 | No | No |
| IE6+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
- Returns
void- Throws
INDEX_SIZE_ERR,NO_MODIFICATION_ALLOWED_ERR
Example
var sentence = document.createTextNode
("When you're smiling, the whole world smiles with you.");
sentence.deleteData(0, 21);
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
deleteData method to remove the first 22 characters
(the characters between index 0 and
21 inclusive).
The final result is a single
Text node with the data (and
nodeValue) the whole world smiles
with you., that has a length of
32.
If we then did this:
sentence.deleteData(15, 999);
The
second argument is much larger than the total length of the string, so
everything from character offset 15 to the end of the
string will be deleted, and we'd end up with a Text
node with the data (and nodeValue) the whole world, that
has a length of 15.
Arguments
- offset (
unsigned long) required The character offset from which to start removing.
- count (
unsigned long) required The number of characters to delete. If offset plus count exceeds the length of the data then everything from offset to the end is deleted.
Description
Delete a string from this character data, between specified offsets.
After a successful
operation, the data and length
properties of the node reflect the change.
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.
Compatibility
| 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.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.