사이트 내 전체검색

 

Child Selector (“parent > child”) 본인의 하위 div 선택 Selects direct ch…

페이지 정보

로빈 조회 18회 2019-02-03 11:29

본문

<div id="..."><img src="..."></div>


Ways to refer to a child in jQuery. I summarized it in the following jQuery:


$(this).find("img"); // any img tag child or grandchild etc... 
$(this).children("img"); //any img tag child that is direct descendant
$(this).find("img:first") //any img tag first child or first grandchild etc...
$(this).children("img:first") //the first img tag  child that is direct descendant
$(this).children("img:nth-child(1)") //the img is first direct descendant child
$(this).next(); //the img is first direct descendant child
$(this).children("img:first")


$("#"+$(this).attr("id")+" img:first")
$(this).children()[0]
$(' > img', this).attr("src");
$('#divid > img').attr("src");


<div class="mydiv">
    <img src="test.png" alt="3">
    <img src="test.png" alt="4">
</div>
 $(this).find("img:last-child").attr("alt")
                  OR
 $(this).children("img:last-child").attr("alt")


<div class="mydiv">
    <img class='first' src="test.png" alt="3">
    <img class='second' src="test.png" alt="4">
</div>
$(this).find(".first").attr("alt")
 $(this).find("img.first").attr("alt")
추천0

댓글목록

등록된 댓글이 없습니다.

 

회원로그인

접속자집계

오늘
643
어제
743
최대
3,566
전체
2,335,089