Rebeltrooper
Rebeltrooper

Reputation: 5

toogle in jquery, change divs but if statement not work

im working on this, im trying to show 1 div at the time but i cant make the divs change to show only 1 option:

$(document).ready(function(){  
    $("#boton1").click(function () {
        $('#tdecredito').Toggle("slow");
    });
    $("#boton3").click(function () {
        $('#tdecredito').Toggle("slow");
    });
    $("#boton2").click(function () {
        $('#deposito').Toggle("slow");
    });
    $("#boton4").click(function () {
        $('#deposito').Toggle("slow");
    });

    var isVisible = $( "#tdecredito" ).is( ":visible" );
    var isHidden = $( "#tdecredito" ).is( ":hidden" );
    var isVisibleb = $( "#deposito" ).is( ":visibleb" );
    var isHiddenb = $( "#deposito" ).is( ":hiddenb" );

    if($('#tdecredito').is(":visible")) 
    {
        $('#deposito').hide(":hiddenb"); 
    } 
    else($('#deposito').is(":visibleb")) 
    {
        $('#tdecredito').hide(":hidden"); 
    }     
}); 

test page:Test page

Upvotes: 0

Views: 78

Answers (1)

Samir Alajmovic
Samir Alajmovic

Reputation: 3283

I don't know why you need 4 buttons and why you need the is visible part. Here is one solution http://jsfiddle.net/x3FCx/2/.

Simply start with one hidden element, and as you click buttons, both of the divs get toggled, meaning, the one who is visible gets hidden and the one who is hidden gets visible.

$(document).ready(function(){  
$("#boton1").click(function () {
    $('#tdecredito').toggle("slow");
    $('#deposito').toggle("slow");
});
$("#boton3").click(function () {
    $('#tdecredito').toggle("slow");
    $('#deposito').toggle("slow");
});
$("#boton2").click(function () {
    $('#tdecredito').toggle("slow");
    $('#deposito').toggle("slow");
});
$("#boton4").click(function () {
    $('#tdecredito').toggle("slow");
    $('#deposito').toggle("slow");
});

$('#deposito').hide();

});

Upvotes: 1

Related Questions