ออบเจ็กต์ Del ของ HTML DOM เกี่ยวข้องกับองค์ประกอบ HTML <del> ใช้แทนองค์ประกอบ <del> ใช้ Del object สร้างและเข้าถึงองค์ประกอบ <del> ได้
คุณสมบัติ (Properties)
| ลำดับ | คุณสมบัติและคำอธิบาย |
|---|---|
| 1 | cite ตั้งค่าหรือคืนค่าของแอตทริบิวต์ cite ของข้อความที่ลบ |
| 2 | dateTime ตั้งค่าหรือคืนค่าของแอตทริบิวต์ datetime ของข้อความที่ลบ |
ไวยากรณ์ (Syntax)
var p = document.createElement("DEL");
ตัวอย่าง (Example)
<!DOCTYPE html> <html> <body>
<h2>del object example</h2>
<p>Click on the below button to create a DEL element with some text.</p>
<button onclick="delCreate()">CREATE</button>
<br><br>
<script>
function delCreate() {
var d= document.createElement("DEL");
var t = document.createTextNode("Deleted text is here");
d.appendChild(t);
document.body.appendChild(d);
}
</script> </body> </html>
ผลลัพธ์ (Output)
ผลลัพธ์ที่ได้:

เมื่อคลิกปุ่ม CREATE:

คำอธิบายโค้ด
สร้างปุ่ม CREATE ทำงาน delCreate() เมื่อคลิก:
<button onclick="delCreate()">CREATE</button>
delCreate() สร้าง <del> element ด้วย createElement() เก็บในตัวแปร d สร้าง text node ด้วย createTextNode() เพิ่ม text node เข้า <del> ด้วย appendChild() เพิ่ม <del> พร้อม text node เข้า document body:
function delCreate() {
var d= document.createElement("DEL");
var t = document.createTextNode("Deleted text is here");
d.appendChild(t);
document.body.appendChild(d);
}