jQuery ต่อท้าย ()เมธอด
ตัวอย่าง
แทรก <span> องค์ประกอบที่ส่วนท้ายของแต่ละ <p> องค์ประกอบ:
$("button").click(function(){
$("<span>Hello World!</span>").appendTo("p");
});
ความหมายและการใช้งาน
appendTo() วิธีการแทรกองค์ประกอบ HTML ที่ส่วนท้ายขององค์ประกอบที่เลือก
เคล็ดลับ:ในการแทรกองค์ประกอบ HTML ที่จุดเริ่มต้นขององค์ประกอบที่เลือก ใช้วิธี prependTo ()
ไวยากรณ์
$(content).appendTo(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 at the end of the selected elements. |
selector | Required. Specifies on which elements to append the content to |
ลองด้วยตัวคุณเอง - ตัวอย่าง
วิธีการใช้ appendTo() วิธีการแทรกองค์ประกอบที่มีอยู่ที่ส่วนท้ายของแต่ละองค์ประกอบที่เลือก