วิธี HTML DOM Element insertAdjacentText()
- หน้าก่อนหน้า insertAdjacentHTML()
- หน้าต่อไป insertBefore()
- กลับไปยังด้านบน วัตถุ HTML DOM Elements
คำอธิบายและวิธีใช้
insertAdjacentText()
วิธีการใส่ข้อความเข้าไปในตำแหน่งที่กำหนด
ตำแหน่งที่ถูกต้อง:
ค่า | รายละเอียด |
---|---|
afterbegin | หลังจากเริ่มต้นองค์ประกอบ |
afterend | หลังองค์ประกอบ |
beforebegin | ก่อนองค์ประกอบ |
beforeend | ก่อนจบขององค์ประกอบ |
ตัวอย่าง
ตัวอย่าง 1
ใส่ข้อความหลังจากตัวอย่าง
const h2 = document.getElementById("myH2"); let text = "My inserted text"; h2.insertAdjacentText("afterend", text);
ตัวอย่าง 2
ใช้ "afterbegin":
const h2 = document.getElementById("myH2"); let text = "My inserted text"; h2.insertAdjacentText("afterbegin", text);
ตัวอย่าง 3
ใช้ "beforebegin":
h2.insertAdjacentText("beforebegin", text);
ตัวอย่าง 4
ใช้ "beforeend":
h2.insertAdjacentText("beforeend", text);
คำสั่ง
element.insertAdjacentText(ตำแหน่ง, text)
หรือ
node.insertAdjacentText(ตำแหน่ง, text)
ประกาศ
ประกาศ | รายละเอียด |
---|---|
ตำแหน่ง |
สำคัญ。
|
text | ข้อความที่ต้องการใส่ |
เบราเซอร์สนับสนุน
ทั้งหมดเบราเซอร์ทุกตัวเน้น element.insertAdjacentText()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน | สนับสนุน |
- หน้าก่อนหน้า insertAdjacentHTML()
- หน้าต่อไป insertBefore()
- กลับไปยังด้านบน วัตถุ HTML DOM Elements