jQuery หลังจาก ()เมธอด

❮ วิธีการ jQuery HTML/CSS

ตัวอย่าง

แทรกเนื้อหาหลังแต่ละ <p> องค์ประกอบ:

$("button").click(function(){
  $("p").after("<p>Hello world!</p>");
});

ความหมายและการใช้งาน

เมธอด after() แทรกเนื้อหาที่ระบุหลังองค์ประกอบที่เลือก

เคล็ดลับ:หากต้องการแทรกเนื้อหาก่อนองค์ประกอบที่เลือก ให้ใช้ before()วิธีการ


ไวยากรณ์

$(selector).after(content,function(index))

Parameter Description
content Required. Specifies the content to insert (can contain HTML tags)

Possible values:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index) Specifies a function that returns the content to insert
  • index - Returns the index position of the element in the set

ลองด้วยตัวคุณเอง - ตัวอย่าง


แทรกเนื้อหาด้วยเมธอด after()


วิธีการใช้ฟังก์ชันเพื่อแทรกเนื้อหาหลังจากองค์ประกอบที่เลือก


❮ วิธีการ jQuery HTML/CSS