How to enable / disable a Div when clicking the checkBox [duplicate]

-8

How to enable and disable a div by clicking checkbox

$("#chkBloqueio").click(function() {
  if ($("#chkBloqueio").attr('checked') == true) {
    $("#divBloqueio").attr('display', 'inline');
  } else {
    $("#divBloqueio").attr('display', 'none');
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="divBloqueio" runat="server" style="display:none"></div>
    
asked by anonymous 06.09.2018 / 16:42

1 answer

1

It would look like this:

$('#chkBloqueio').on('change', function () {
    if ($(this).is(':checked')) {
        $('#divBloqueio').css('display', 'block');
    }
    else {
        $("#divBloqueio").css('display', 'none');
    }
});
    
06.09.2018 / 16:47