본문 바로가기

jQuery

[jQuery] each 메소드

반응형

[jQuery] each 메소드


 each.html

<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>each 메소드</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {

        // 묵시적 반복
        jQuery("h2").css("color", "red");   
       
        jQuery("h2").eq(1).css("color", "blue");
       
        var bgcolor=new Array("yellow", "green", "skyblue");
       
        // 명시적 반복 => each(function([index]) { 명령; ... })
        $("h2").each(function(index) {
            $(this).css("background-color", bgcolor[index]);
        });
    });
</script>
</head>
<body>
    <h1>each 메소드</h1>
    <hr/>
    <h2>ecah 메소드 호출-1</h2>
    <h2>ecah 메소드 호출-2</h2>
    <h2>ecah 메소드 호출-3</h2>
</body>
</html>

 출력결과


반응형

'jQuery' 카테고리의 다른 글

[jQuery] attr 메소드  (0) 2015.12.20
[jQuery] css 메소드  (0) 2015.12.20
[jQuery] eq 선택자  (0) 2015.12.20
[jQuery] NOT 선택자  (0) 2015.11.16
[jQuery] 필터 선택자  (0) 2015.11.16