찾기메소드

조수경·2021년 11월 25일
0

HTML

목록 보기
86/96

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel = "stylesheet" href = "../css/mystyle.css" type="text/css">
<script src="../js/jquery-3.6.0.min.js"></script>

<script>
 $(function(){
	 
	 $('p').on('click', function(){
		 
		 if($(this).parent().is('.dd')){
	
			 aa = $(this).clone();
			 aa.css('color', 'red')
			 aa.appendTo($(this).parent());
			 
		 }else{
			 alert("작업 대상이 아닙니다");
		 }
	 })
	 
 })
</script>

</head>
<body>

<div class = "box">
   p태그를 클릭 시 부모가.dd인지 비교 - .is(selector)<br>
   p태그 클릭 이벤트 시 this로 받는다<br>
   $(this).parent().is('.dd)<br>
   <br>
  <div class="dd" id = "result1">
   <p>무궁화 꽃이 피었습니다</p>
  </div>
  
  <p>은주는 예쁘다</p>
  
  <div class="dd" id = "result2">
   <p>울긋불긋 단풍이 ~~</p>
  </div>
  
</div>
</body>
</html>

은주는 예쁘다를 누르면

profile
신입 개발자 입니다!!!

0개의 댓글