텍스트 노드가 상속 받은 CharacterData 객체는 문자를 제어할 수 있는 다양한 API를 제공한다. 아래는 조작과 관련된 API들의 목록이다.
- appendData()
- deleteData()
- insertData()
- replaceData()
- substringData()
<!DOCTYPE html> <html> <head> <style> #target{ font-size:77px; font-family: georgia; border-bottom:1px solid black; padding-bottom:10px; } p{ margin:5px; } </style> </head> <body> <p id="target">Cording everybody!</p> <p> data : <input type="text" id="datasource" value="JavaScript" /></p> <p> start :<input type="text" id="start" value="5" /></p> <p> end : <input type="text" id="end" value="5" /></p> <p><input type="button" value="appendData(data)" onclick="callAppendData()" /> <input type="button" value="deleteData(start,end)" onclick="callDeleteData()" /> <input type="button" value="insertData(start,data)" onclick="callInsertData()" /> <input type="button" value="replaceData(start,end,data)" onclick="callReplaceData()" /> <input type="button" value="substringData(start,end)" onclick="callSubstringData()" /></p> <script> var target = document.getElementById('target').firstChild; var data = document.getElementById('datasource'); var start = document.getElementById('start'); var end = document.getElementById('end'); function callAppendData(){ target.appendData(data.value); } function callDeleteData(){ target.deleteData(start.value, end.value); } function callInsertData(){ target.insertData(start.value, data.value); } function callReplaceData(){ target.replaceData(start.value, end.value, data.value); } function callSubstringData(){ alert(target.substringData(start.value, end.value)); } </script> </body> </html>