jQuery แทนที่ด้วย ()เมธอด
ตัวอย่าง
แทนที่ <p> องค์ประกอบแรกด้วยข้อความใหม่:
$("button").click(function(){
$("p:first").replaceWith("Hello world!");
});
ความหมายและการใช้งาน
ReplaceWith() วิธีการแทนที่องค์ประกอบที่เลือกด้วยเนื้อหาใหม่
ไวยากรณ์
$(selector).replaceWith(content,function(index))
Parameter | Description |
---|---|
content | Required. Specifies the content to insert (can contain HTML tags)
Possible values:
|
function(index) | Optional. Specifies a function that returns the content to replace
|
ลองด้วยตัวคุณเอง - ตัวอย่าง
วิธีใช้ฟังก์ชันเพื่อแทนที่องค์ประกอบที่เลือกด้วยเนื้อหาใหม่