메인메뉴 바로가기

HOME으로 가기


제이쿼리 .each()

페이지 정보

profile_image
작성자 너갱이
댓글 0건 조회 4,339회 작성일 15-01-29 12:19

본문

for문과 비슷하게각 객체를 순차적으로 실행한다.

 

$("#btns > button").each(function(idx, elem){

$(elem).html(idx+"번 버튼")

}) 

 

 

 

 

 

[예문]

-------------- HTML ---------------

<ul id="btns">
 <li><button>1</button></li>
 <li><button>2</button></li>
 <li><button>3</button></li>
 <li><button>4</button></li>
</ul>

 

 

------------------ JS ----------------

//각 선택요소 별로 각각 실행... (#sample객체 자식노드 들)

$("#btns").children().each(function(idx, elem){   //기본 인자값 - index, item
console.log( idx +" : "+$(elem).html() );

});

 

 

---------- // Output ------------

0 : <button>1</button>

1 : <button>2</button>

2 : <button>3</button>

3 : <button>4</button> 

 

댓글목록

등록된 댓글이 없습니다.