jQuery ( ": has (selector)")

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

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-11-24 조회 2,538
jQuery 17-11-24 조회 2,697
jQuery 17-11-21 조회 2,921
jQuery 17-11-21 조회 3,132
jQuery 17-11-21 조회 2,347
jQuery 17-11-10 조회 3,342
jQuery 17-11-10 조회 2,806
jQuery
[jQuery]
17-11-10 조회 2,157
JavaScript 17-11-09 조회 3,238
jQuery
[jQuery]
17-11-08 조회 1,969
jQuery 17-11-08 조회 2,234
jQuery 17-11-08 조회 2,334
jQuery 17-10-24 조회 2,114
jQuery 17-10-24 조회 2,189
jQuery
[jQuery]
17-10-24 조회 1,874
jQuery 17-10-20 조회 2,441
jQuery 17-10-20 조회 2,917
jQuery
[jQuery]
17-10-20 조회 2,208
jQuery 17-10-19 조회 1,901
jQuery
[jQuery]
17-10-19 조회 2,329
jQuery 17-10-19 조회 5,925
기타 17-10-19 조회 3,660
jQuery
[jQuery]
17-10-17 조회 2,053
jQuery 17-10-17 조회 2,208
jQuery 17-10-17 조회 2,306
PHP 17-10-16 조회 5,615
node.js 17-10-13 조회 4,652
jQuery 17-10-12 조회 2,699
jQuery 17-10-12 조회 2,142
jQuery 17-10-12 조회 1,673