View and hide Panel

-1

I mounted a code that when the condition is true shows the component on the screen and when it is false hides the component. When the condition is false the first time it hides, but changing to true condition the component does not appear.

Follow the code below:

function VerificarDeposito(){

    if ($('#DadosComplementares').val()=="SIM"){

        document.getElementById('Painel4').style.display = 'true';
    }else{
        document.getElementById('Painel4').style.display = 'none'; 
    };
}
    
asked by anonymous 06.02.2018 / 15:54

2 answers

1

If you are using jQuery , why use getElementById ?

You can use show and hide of jQuery as well:

if ($('#DadosComplementares').val()=="SIM") {
    $('#Painel4').show();
} else {
    $('#Painel4').hide(); 
};
    
06.02.2018 / 16:02
1

If the value of the element never changes, it will never reappear. Change the value of the element to toggle visibility:

function VerificarDeposito(){
    if ($('#DadosComplementares').val()=="SIM"){
        $('#DadosComplementares').val("NÃO");
        $('#Painel4').show();
    }else{
        $('#DadosComplementares').val("SIM");
        $('#Painel4').hide(); 
    };
}

Example:

function VerificarDeposito(){
    if ($('#DadosComplementares').val()=="SIM"){
        $('#DadosComplementares').val("NÃO");
        $('#Painel4').show();
    }else{
        $('#DadosComplementares').val("SIM");
        $('#Painel4').hide(); 
    }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttononclick="VerificarDeposito()">Verificar</button>
<br>
<input type="text" value="NÃO" id="DadosComplementares" />
<br>
<div id="Painel4">
   painel4
</div>
    
08.02.2018 / 00:53