선택한 요소에서 주어진 선택자가 있는지 판별합니다.
- $("선택자").is("선택자");
- $("선택자").is("변수");
- $("선택자").is("함수");
선택한 요소에서 주어진 선택자가 있는지 판별하여 있으며 true를 반환합니다.
<!-- html -->
<input type="checkbox" id="example" checked">example
<!-- js -->
var chk = $("input[type=checkbox]");
console.log(chk.prop("checked")); //true
console.log(chk.is(":checked")); //true
위의 html에서 checked속성을 주었기때문에 checkbox는 true 값을 반환한다.
// 타입(type) 확인
console.log(jQuery.type(chk.prop("checked"))); //boolean
console.log(jQuery.type(chk.is(":checked"))); //boolean
jQuery.type()로 반환되는 값의 타입(type)을 확인하면 두 개의 방식 모두 boolean 타입을 갖는다.