수

jQuery ( ": has (selector)")

· 2017-10-12 (목) 16:38:47 · 2736

jQuery ( ": has (selector)")


설명 : 지정된 선택기와 일치하는 요소를 하나 이상 포함하는 요소를 선택합니다.


이 표현식 $( "div:has(p)" )은 a <div>가 a 와 일치하는 경우에만 <p>존재합니다.


추가 참고 사항 :


:has()jQuery 확장이며 CSS 사양의 일부가 아니기 때문에 사용하는 쿼리 :has()는 기본 DOM querySelectorAll()메서드 에서 제공하는 성능 향상을 이용할 수 없습니다 . 최신 브라우저의 성능을 높이려면 $( "your-pure-css-selector" ).has( selector/DOMElement )대신 사용하십시오.

예:

그 안에 단락이있는 모든 div에 "test"클래스를 추가합니다.



<!doctype html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>has demo</title>

  <style>

  .test {

    border: 3px inset red;

  }

  </style>

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>

 

<div><p>Hello in a paragraph</p></div>

<div>Hello again! (with no paragraph)</div>

 

<script>

$( "div:has(p)" ).addClass( "test" );

</script>

 

</body>

</html>

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
jQuery 17-10-11 조회 2,481
jQuery 17-10-11 조회 1,950
jQuery 17-10-11 조회 2,050
jQuery 17-09-29 조회 2,276
jQuery 17-09-29 조회 2,510
jQuery 17-09-29 조회 2,056
jQuery 17-09-26 조회 1,979
jQuery 17-09-26 조회 2,069
jQuery
[jQuery]
17-09-26 조회 1,841
jQuery 17-09-22 조회 2,085
jQuery 17-09-22 조회 2,146
jQuery 17-09-22 조회 2,112
jQuery 17-09-21 조회 2,306
jQuery 17-09-21 조회 2,258
jQuery 17-09-21 조회 2,125
jQuery 17-09-19 조회 2,183
jQuery 17-09-19 조회 1,920
jQuery
[jQuery]
17-09-19 조회 1,922
jQuery
[jQuery]
17-09-18 조회 2,089
jQuery 17-09-18 조회 2,000
jQuery 17-09-18 조회 1,704
jQuery 17-09-14 조회 2,118
jQuery 17-09-14 조회 1,810
jQuery 17-09-14 조회 2,051
jQuery 17-09-11 조회 2,440
jQuery 17-09-11 조회 2,478
jQuery 17-09-11 조회 1,994
jQuery 17-09-10 조회 2,058
jQuery 17-09-10 조회 2,494
jQuery
[jQuery]
17-09-10 조회 1,943