Javascript/jQuery

현재 주소 링크에 addClass하기/ 현재 주소 herf에서 찾기

<script>
    /* 세부페이지 좌측 메뉴 링크 on 시작*/
    $(function() {
        $('.nav .panel').each(function(i) {
            $('.nav .panel').eq(i).find('a').each(function(e) {
                if ($(this).attr('href') == "<?=$_SERVER['REQUEST_URI'] ?>") {
                    $('.nav .panel').addClass('hidden');
                    $(this).parents('li').parents('.panel').removeClass('hidden');
                }else{
                    
                }
            });
        });

        $('.depth2').each(function(i) {
            console.log($('.depth2').eq(i))
            if ($('.depth2').eq(i).children('.sub_menu').length == 0) {
                if ($('.depth2').eq(i).find('.link_lnb').attr('href') == "<?=$_SERVER['REQUEST_URI'] ?>") {
                    $('.depth2').eq(i).addClass('on');
                };
            };
        });
    });
    /* 세부페이지 좌측 메뉴 링크 on 끝*/
</script>
728x90
반응형