jQuery is()เมธอด

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

ตัวอย่าง

หากพาเรนต์ของ <p> เป็นองค์ประกอบ <div> ให้แจ้งเตือนข้อความ:

if ($("p").parent().is("div")) {
  alert("Parent of p is div");
}

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

is() วิธีการตรวจสอบว่าหนึ่งในองค์ประกอบที่เลือกตรงกับ selectorElement


ไวยากรณ์

$(selector).is(selectorElement,function(index,element))

Parameter Description
selectorElement Required. Specifies a selector expression, element or a jQuery object to match the current set of elements against. Returns true if there is at least one match from the given argument, and false if not.
function(index,element)

Optional. Specifies a function to run for the group of selected elements.

  • index - the index position of the element
  • element - the current element (the "this" selector can also be used)

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