each()

# Work/└ jQuery 2014. 1. 9. 00:06 |
반응형

each() :  jQuery 객체 만큼 반복하고, 선택된 요소들에 함수를 실행.

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

<script type="text/javascript">

$(function() {

$('h1').addClass(function(index) {

return 'highlight' + index;

});

});

</script>

<style type="text/css">

.highlight0 {color:red; }

.highlight1 {color:blue; }

.highlight2 {color:green; }

.highlight3 {color:yellow; }

</style>

</head>


<body>

<h1>111</h1>

<h1>222</h1>

<h1>333</h1>

<h1>444</h1>

<h1>555</h1>

같은 결과를 갖는 다른 제이쿼리 표현식

$('h1').each(function (index, item) {

$(item).addClass('highlight' + index);

});


상세 설명 및 예제 - http://www.jquerykorea.pe.kr/xe/index.php?_filter=search&mid=document&search_keyword=each&search_target=title&document_srl=3623

반응형

'# Work > └ jQuery' 카테고리의 다른 글

반응형 슬라이드메뉴 Slidebars.js  (0) 2014.02.05
jquery selector의 종류 (스크랩. 내용 중복 유)  (0) 2014.01.21
jQuery Api 정리 2  (0) 2012.04.26
show & hide  (0) 2012.04.26
jquery 내용 정리  (0) 2012.04.18
호정찐