jQuery wrapInner()เมธอด

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

ตัวอย่าง

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

$("button").click(function(){
  $("p").wrapInner("<b></b>");
});

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

เมธอด wrapInner() จะล้อมองค์ประกอบ HTML ที่ระบุรอบๆ เนื้อหา (innerHTML) ของแต่ละองค์ประกอบที่เลือก


ไวยากรณ์

$(selector).wrapInner(wrappingElement,function(index))

Parameter Description
wrappingElement Required. Specifies what HTML element(s) to wrap around the content of each selected element

Possible values:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index) Optional. Specifies a function that returns the wrapping element
  • index - Returns the index position of the element in the set

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


วิธีใช้ document.createElement() เพื่อสร้างองค์ประกอบ และล้อมรอบเนื้อหาของแต่ละองค์ประกอบที่เลือก


การใช้ฟังก์ชันเพื่อระบุสิ่งที่จะล้อมเนื้อหาของแต่ละองค์ประกอบที่เลือก


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