프로그램

jQuery parent() Method

다온다올과함께 2021. 12. 31. 15:28

The parent() method returns the direct parent element of the selected element.

(parent() 메서드는 선택한 요소의 직접적인 부모 요소를 반환합니다.)

 

 

 

html

<div>
	<h3>Hello</h3>
	<div class="d1">
		<p class="p1">
			Lorem Ipsum Dolor
		</p>
	</div>
</div>

 

 

css

.color {
	color:red;
	font-size:2em;
	font-weight:bold;
}

 

 

Jquery

$( '.p1' ).parent( 'div.d1' ).css( 'font-size', '2em');
$( '.p1' ).parent().siblings('h3').addClass('color');

 

Result(결과)

 

반응형