jQuery แต่ละ ()เมธอด

❮ วิธีการข้ามผ่าน jQuery

ตัวอย่าง

แจ้งเตือนข้อความของแต่ละองค์ประกอบ <li>:

$("button").click(function(){
  $("li").each(function(){
    alert($(this).text())
  });
});

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

each() วิธีการระบุฟังก์ชันที่จะเรียกใช้สำหรับแต่ละองค์ประกอบที่ตรงกัน

เคล็ดลับ: return false สามารถใช้เพื่อหยุดการวนซ้ำในช่วงต้น


ไวยากรณ์

$(selector).each(function(index,element))

Parameter Description
function(index,element) Required. A function to run for each matched element.
  • index - The index position of the selector
  • element - The current element (the "this" selector can also be used)

❮ วิธีการข้ามผ่าน jQuery