특정 요소를 가지고 있는 요소를 선택하는 방법 - .has()

has로 특정 요소를 가지고 있는 요소를 선택할 수 있습니다.
0 min read

.has()

.has()로 특정 요소를 가지고 있는 요소를 선택할 수 있습니다.

 

기본형

.has( selector )

예를 들어

$( 'h1' ).has( 'span' )

은 span 요소를 가지고 있는 h1 요소를 선택합니다.

 

예제

span 요소를 포함하고 있는 h1 요소의 글자색을 빨간색으로 만듭니다.

<h1>Lorem Ipsum Dolor</h1>
<h1>Lorem <span>Ipsum</span> Dolor</h1>
$( document ).ready( function() {
  $( 'h1' ).has( 'span' ).css( 'color', 'red' );
});

You may like these posts

Post a Comment