jQuery ( ": has (selector)")

· 8년 전 · 2251

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>

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

개발자팁

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

+
분류 제목 글쓴이 날짜 조회
jQuery 8년 전 조회 1,699
jQuery
[jQuery]
8년 전 조회 1,381
jQuery 8년 전 조회 2,010
jQuery 8년 전 조회 2,468
jQuery
[jQuery]
8년 전 조회 1,742
jQuery 8년 전 조회 1,451
jQuery
[jQuery]
8년 전 조회 1,886
jQuery 8년 전 조회 5,464
기타 8년 전 조회 3,212
jQuery
[jQuery]
8년 전 조회 1,588
jQuery 8년 전 조회 1,759
jQuery 8년 전 조회 1,862
PHP 8년 전 조회 5,189
node.js 8년 전 조회 4,186
jQuery 8년 전 조회 2,252
jQuery 8년 전 조회 1,698
jQuery 8년 전 조회 1,251
jQuery 8년 전 조회 1,972
jQuery 8년 전 조회 1,467
jQuery 8년 전 조회 1,585
jQuery 8년 전 조회 1,797
jQuery 8년 전 조회 2,046
jQuery 8년 전 조회 1,586
jQuery 8년 전 조회 1,516
jQuery 8년 전 조회 1,600
jQuery
[jQuery]
8년 전 조회 1,473
jQuery 8년 전 조회 1,616
jQuery 8년 전 조회 1,672
jQuery 8년 전 조회 1,681
jQuery 8년 전 조회 1,862
🐛 버그신고