each( ) 메소드

<aside> 💡 $.each(object, function(index, item){ } ) 의 형식으로 사용 index → 배열의 인덱스 또는 객체의 키를 의미 item → 해당 인덱스나 키가 가진 값을 의미

</aside>

<div id="area1"></div>
    <script>
        $(function(){
            var arr = [
                {name: '네이버', link: '<http://www.naver.com>'},
                {name: '구글', link: '<http://www.google.com>'},
                {name: 'w3c', link: '<http://www.w3c.com>'},
                {name: 'w3schools', link: '<http://www.w3schools.com>'}
            ];
            $.each(arr, function(index, item){
                var output = "";
                output = "<h2><a href = " + item.link + ">" + item.name + "</a></h2>";
                $("#area1").html($("#area1").html() + output);
            });
        });
    </script>

→ 네이버, 구글, w3c, w3schools 출력, 클릭 시 설정한 링크로 이동 가능


is( ) 메소드

<h3 class="test">test1</h3>
    <h3>test2</h3>
    <h3 class="test">test3</h3>
    <h3 class="test">test4</h3>
    <h3>test5</h3>
    <h3 class="test">test6</h3>

    <script>
        $(function(){
            $('h3').each(function(){
                if($(this).is('.test')){
                    $(this).css({"background":"orangered", "color":"white"});
                }
            });
        });
    </script>

Untitled


$.noConflict 별칭 부여

<h1 id="test">noConflict() 테스트</h1>
    <script>
        $(function(){
            var jq = $.noConflict();
            var jq1 = jq.noConflict();
            jq('#test').css('color', 'red');
            jq1('#test').css('background', 'purple');
        });
    </script>