본문 바로가기

Web/javascript & jQuery

index로 두가지 버튼 제어

반응형
$('.btn_t').bind('click', function () {
    var target = $(this).parents('.m_dshalf').index();
    var target1 = $('#m_brandwrap .m_ds_pos');
    var target2 = $('#m_schmid .m_ds_pos');

    if (target == 0) {
        if (target1.is(':visible')) {
            target1.parent().removeClass('active');
            $('.dimmed').hide();
        } else if(!target1.is(':visible') && target2.is(':visible')) {
            target1.parent().addClass('active');
            target2.parent().removeClass('active');
        } else if(!target1.is(':visible') && !target2.is(':visible')) {
            target1.parent().addClass('active');
            $('.dimmed').show();
        };
    } else if (target == 1) {
        if (target2.is(':visible')) {
            target2.parent().removeClass('active');
            $('.dimmed').hide();
        } else if(!target2.is(':visible') && target1.is(':visible')) {
            target1.parent().removeClass('active');
            target2.parent().addClass('active');
        } else if(!target2.is(':visible') && !target1.is(':visible')) {
            target2.parent().addClass('active');
            $('.dimmed').show();
            
        };
    };
});
반응형