The deleteData() method works like replaceData(), only that it excepts two parameters, where as the replaceData() method has a 3rd parameter which excepts a string value that is used in replacing text.
Here is an example of using "deleteData()"
<div id="mydiv">Here is some text</div>
|
|
The goal is to delete the text "Here is " from the text node. The first job is to grab the div by using the "getElementById()" method, and then grab the first child (which is the text node we want to alter) using "firstChild".
Now that we have our text node, we now can use "deleteData()" to delete the text. The deleteDate() method excepts two parameters as stated above.
deleteData(start, end)
|
|
start is a number which indicates where to start the deleting from. Remember that indexing starts at 0, so the first letter in the string is "H". If you look at the example script above, and look at the start value, you will see it is 0. This is because I want delete "Here is " from the text node.
end indicates the length of the amount of characters you want to delete. So in this case, I set the length to eight.
So the text to be deleted now, would be the text in red.
Here is some text
You would then be left with "some text".
| Discuss Tutorial: Using deleteData() | 0 Comments |