jquery .is()

김종민·2023년 8월 14일
0

js

목록 보기
15/25
post-thumbnail

.is()

선택한 요소에서 주어진 선택자가 있는지 판별합니다.

문법

  • $("선택자").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 타입을 갖는다.

profile
웹 퍼블리셔의 코딩 일기

0개의 댓글

관련 채용 정보