0

I have an array of checkboxes which can be used in a sort of calendar app. Whenever the checkbox gets checked, a label should become visible. My HTML looks something like this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    CheckVisibility();
})

function CheckVisibility(){
  if($('#cb').is(':checked')){
    $('#label').show()
  }
  else{
    $('#label').hide()
  }
}
</script>
<table>
    <tr>
        <td><input type=checkbox id="cb" onchange="CheckVisibility()"/></td>
        <td><label id="label" style="display : none">Monday</label></td>
    <tr>
</table>

And it works fine on first load. However, when I return to the previous page, the checkbox is still checked. This is the behaviour I want, but it won't get registered as "checked" when passing $(document).ready fires of CheckVisibility(). Any idea's?

Kiiiieeeeuuuw
  • 113
  • 1
  • 1
  • 10
  • Does this answer your question? [Why does the checkbox stay checked when reloading the page?](https://stackoverflow.com/questions/299811/why-does-the-checkbox-stay-checked-when-reloading-the-page) – DarkBee Sep 09 '21 at 08:41
  • It didn't, since I'd like the checkbox to remain checked. Thanks for the suggestion, I've edited my question accordingly. – Kiiiieeeeuuuw Sep 09 '21 at 13:55
  • 1
    I see, you should try `$('#cb').prop('checked');` instead – DarkBee Sep 09 '21 at 14:23

0 Answers0