Met Text Deletedata
## XML DOM CharacterData.deleteData() Method
The `deleteData()` method is a standard API of the XML DOM `CharacterData` interface (implemented by `Text`, `Comment`, and `CDATASection` nodes). It is used to delete a specified range of characters from a text node.
---
## Definition and Usage
The `deleteData()` method removes a sequence of characters from the data of a text node, starting at a specified offset and spanning a specified length.
Once this method is executed, the node's content is updated in place, and the DOM tree reflects the change immediately.
---
## Syntax
```javascript
characterDataNode.deleteData(offset, count);
```
### Parameters
| Parameter | Type | Required / Optional | Description |
| :--- | :--- | :--- | :--- |
| `offset` | `Number` | **Required** | The zero-based index at which to start deleting characters. |
| `count` | `Number` | **Required** | The number of characters to delete. |
### Return Value
* This method does not return any value (`undefined`).
### Exceptions
* **IndexSizeError**: Thrown if `offset` is negative or greater than the total number of characters in the node, or if `count` is negative.
---
## Code Example
The following example loads an XML document, ["books.xml"](/try/demo_source/books.xml), into `xmlDoc` using `loadXMLDoc()`, and deletes a portion of the text from the first `` element's text node.
### Source XML Structure (books.xml)
Assume the first `` element contains the following text:
```xml
Everyday Italian
```
### JavaScript Implementation
```javascript
// Load the XML document
var xmlDoc = loadXMLDoc("books.xml");
// Access the text node of the first element
var titleTextNode = xmlDoc.getElementsByTagName("title").childNodes;
// Delete 9 characters starting from index 0 ("Everyday ")
titleTextNode.deleteData(0, 9);
// Output the updated text content
document.write(titleTextNode.data);
```
### Output
```text
Italian
```
---
## Important Considerations
1. **Zero-Based Indexing**: The `offset` parameter is zero-based. Passing `0` targets the very first character of the text node.
2. **Handling Out-of-Bounds `count`**: If the sum of `offset` and `count` exceeds the total length of the text node, all characters from the `offset` to the end of the string will be deleted without throwing an error.
3. **Live DOM Updates**: Any changes made via `deleteData()` are immediately reflected in the active DOM tree and will render on the page if the node is currently bound to the viewport.
YouTip