수

jQuery ( ": has (selector)")

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

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,656
jQuery 17-11-24 조회 2,745
jQuery 17-11-21 조회 2,971
jQuery 17-11-21 조회 3,199
jQuery 17-11-21 조회 2,412
jQuery 17-11-10 조회 3,403
jQuery 17-11-10 조회 2,863
jQuery
[jQuery]
17-11-10 조회 2,198
JavaScript 17-11-09 조회 3,303
jQuery
[jQuery]
17-11-08 조회 2,019
jQuery 17-11-08 조회 2,293
jQuery 17-11-08 조회 2,377
jQuery 17-10-24 조회 2,175
jQuery 17-10-24 조회 2,227
jQuery
[jQuery]
17-10-24 조회 1,925
jQuery 17-10-20 조회 2,537
jQuery 17-10-20 조회 2,971
jQuery
[jQuery]
17-10-20 조회 2,265
jQuery 17-10-19 조회 1,967
jQuery
[jQuery]
17-10-19 조회 2,376
jQuery 17-10-19 조회 5,989
기타 17-10-19 조회 3,708
jQuery
[jQuery]
17-10-17 조회 2,117
jQuery 17-10-17 조회 2,272
jQuery 17-10-17 조회 2,371
PHP 17-10-16 조회 5,683
node.js 17-10-13 조회 4,745
jQuery 17-10-12 조회 2,765
jQuery 17-10-12 조회 2,190
jQuery 17-10-12 조회 1,764