jQuery insertAfter()เมธอด
ตัวอย่าง
แทรก <span> องค์ประกอบหลังแต่ละ <p> องค์ประกอบ:
$("button").click(function(){
$("<span>Hello world!</span>").insertAfter("p");
});
ความหมายและการใช้งาน
เมธอด insertAfter() แทรกองค์ประกอบ HTML หลังองค์ประกอบที่เลือก
เคล็ดลับ:ในการแทรกองค์ประกอบ HTML ก่อนองค์ประกอบที่เลือก ให้ใช้ เมธอดinsertBefore()
ไวยากรณ์
$(content).insertAfter(selector)
Parameter | Description |
---|---|
content | Required. Specifies the content to insert (must contain HTML tags). Note: If content is an existing element, it will be moved from its current position, and inserted after the selected elements. |
selector | Required. Specifies where to insert the content |
ลองด้วยตัวคุณเอง - ตัวอย่าง
วิธีการใช้เมธอด insertAfter() เพื่อแทรกองค์ประกอบที่มีอยู่หลังจากแต่ละองค์ประกอบที่เลือก