Error catching attribute 'checked'

1

JQUERY

$('#caption-item-1').click(function(){
    if($('#boleto-input').checked == true){
        $('doacao-proximo-1').css({'display':'inline-block'});
    }else{
        $('doacao-proximo-1').css({'display':'none'});
    }
})

HTML

<label for="boleto-input">
    <input type="checkbox" name="" id="boleto-input">
    <span class="check-for-bank"></span>
    <img src="img/barcode.jpg">
</label>
...
<p id="doacao-proximo-1" style="display:none;">Próximo</p>
  • I can not get the button to appear when input is checked.
  • The button is as p because when set to button , the page reloads, even with preventDefault()

Thanks if you can help me solve it, or find a way to solve the problem.

    
asked by anonymous 31.01.2017 / 12:21

2 answers

3

I think you forgot about "#" in $('#doacao-proximo-1') . But try this:

$('#caption-item-1').click(function(){
    if($('#boleto-input').is(':checked')) { // <-- altera aqui
        $('#doacao-proximo-1').css({'display':'inline-block'});
    }else{
        $('#doacao-proximo-1').css({'display':'none'});
    }
});
    
31.01.2017 / 12:23
3

Well, it's already been answered, but here's a different way:

$('#caption-item-1').click(function(){
    $('#doacao-proximo-1').css({'display': $('#boleto-input').prop('checked') ? 'inline-block' : 'none'});
});
    
31.01.2017 / 12:31