jQuery is () Phương thức

❮ Phương thức duyệt jQuery

Thí dụ

Nếu phần tử gốc của <p> là một phần tử <div>, hãy cảnh báo một số văn bản:

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

Định nghĩa và Cách sử dụng

Phương thức is () kiểm tra xem một trong các phần tử được chọn có khớp với selectorElement hay không .


Cú pháp

$(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)

❮ Phương thức duyệt jQuery