"JQuery .closest()"의 두 판 사이의 차이

잔글 (Jmnote 사용자가 Closest() 문서를 JQuery .closest() 문서로 옮겼습니다)
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 2명의 중간 판 2개는 보이지 않습니다)
4번째 줄: 4번째 줄:
* '''자신부터 시작하여''' 조건에 맞는 가장 가까운 태그를 상위 방향으로 찾음
* '''자신부터 시작하여''' 조건에 맞는 가장 가까운 태그를 상위 방향으로 찾음


<source lang='html5'>
<syntaxhighlight lang='html5'>
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>


31번째 줄: 31번째 줄:
$( "#ii-a" ).css( "color", "Salmon" );
$( "#ii-a" ).css( "color", "Salmon" );
</script>
</script>
</source>
</syntaxhighlight>
<jsfiddle height='250'>1hdrfy62</jsfiddle>
<jsfiddle height='250'>1hdrfy62</jsfiddle>


37번째 줄: 37번째 줄:
*[[jQuery .parents()]]
*[[jQuery .parents()]]


==참고 자료==
==참고==
*https://api.jquery.com/closest/
*http://www.w3schools.com/jquery/traversing_closest.asp
*http://www.w3schools.com/jquery/traversing_closest.asp


[[분류: jQuery]]
[[분류: jQuery]]

2020년 11월 2일 (월) 02:53 기준 최신판

1 개요[ | ]

jQuery .closest()
  • 첫번째 조상을 반환하는 jQuery 메소드
  • 자신부터 시작하여 조건에 맞는 가장 가까운 태그를 상위 방향으로 찾음
<script src="//code.jquery.com/jquery.min.js"></script>

<ul id="list">
  <li>I</li>
  <li>II
    <ul>
      <li id="ii-a">A</li>
      <li>B
        <ul>
          <li>1</li>
          <li>2</li>
          <li>3</li>
        </ul>
      </li>
      <li>C</li>
    </ul>
  </li>
  <li>III</li>
</ul>

<script>
$( "#ii-a" ).closest( "#list" ).css( "color", "CornflowerBlue" );
$( "#ii-a" ).closest( "ul" ).css( "background", "SkyBlue" );
$( "#ii-a" ).closest( "li" ).css( "background", "Khaki" );
$( "#ii-a" ).css( "color", "Salmon" );
</script>

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}