.has (selector)
설명 : 일치하는 요소 집합을 선택기 또는 DOM 요소와 일치하는 하위 항목이있는 요소로 줄입니다.
DOM 요소 집합을 나타내는 jQuery 객체가 주어지면이 .has()메소드는 일치하는 요소의 하위 집합에서 새 jQuery 객체를 생성합니다. 제공된 선택기는 일치하는 요소의 하위 항목에 대해 테스트됩니다. 하위 요소 중 하나가 선택자와 일치하면 요소가 결과에 포함됩니다.
다음과 같이 중첩 목록이있는 페이지를 고려하십시오.
<ul>
<li>list item 1</li>
<li>list item 2
<ul>
<li>list item 2-a</li>
<li>list item 2-b</li>
</ul>
</li>
<li>list item 3</li>
<li>list item 4</li>
</ul>
이 메소드를 다음과 같이 목록 항목 집합에 적용 할 수 있습니다.
$( "li" ).has( "ul" ).css( "background-color", "red" );
이 호출의 결과는 항목 2의 빨간색 배경입니다 . 하위 항목 중 하나만 <li>있는 항목이기 때문입니다 <ul>.
예:
요소가 다른 요소 안에 있는지 확인하십시오.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>has demo</title>
<style>
.full {
border: 1px solid red;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<ul><li>Does the UL contain an LI?</li></ul>
<script>
$( "ul" ).append( "<li>" +
( $( "ul" ).has( "li" ).length ? "Yes" : "No" ) +
"</li>" );
$( "ul" ).has( "li" ).addClass( "full" );
</script>
</body>
</html>
게시글 목록
| 번호 | 제목 |
|---|---|
| 15969 |
jQuery
.jquery
|
| 15968 |
JavaScript
공휴일을 제외한 시간적용 ON/OFF 스크립트예제 (휴일추가가능)
|
| 15967 |
jQuery
.is()
|
| 15966 |
jQuery
.insertBefore()
|
| 15965 |
jQuery
.insertAfter()
|
| 15964 |
jQuery
.innerWidth ()
|
| 15963 |
jQuery
.innerHeight ()
|
| 15962 |
jQuery
.index()
|
| 15961 |
jQuery
jQuery( ":image" )
|
| 15960 |
jQuery
jQuery ( "# id")
|
| 15959 |
jQuery
.html()
|
| 15958 | |
| 15957 |
jQuery
.hide ()
|
| 15956 |
jQuery
jQuery ( ": hidden")
|
| 15955 |
기타
그누보드5 기본쿼리
|
| 15954 |
jQuery
.height()
|
| 15953 |
jQuery
jQuery ( ": header")
|
| 15952 |
jQuery
.hasClass( className )
|
| 15949 |
PHP
네이버 클로버 tts
3
|
| 15947 |
node.js
네이트온 팀룸으로 메일 수신 확인
1
|
| 15946 |
jQuery
jQuery ( ": has (selector)")
|
| 15945 |
jQuery
attributeHas 선택자
|
| 15944 |
jQuery
.has (selector)
현재글
|
| 15942 |
jQuery
.get (index)
|
| 15941 |
jQuery
.focusin (handler)
|
| 15940 |
jQuery
.focusin (handler)
|
| 15939 |
jQuery
jQuery ( ": focus")
|
| 15938 |
jQuery
.focus (handler)
|
| 15937 |
jQuery
jQuery( ":first" )
|
| 15936 |
jQuery
jQuery ( ": first-of-type")
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기