My goal is to have the div element show when I click on the checkbox and hide when I uncheck it. The code below works fine in terms of functionality.
However, the issue arises when I click on both checkbox1 and checkbox2, causing the div element to override the display.
Below is the code that I am working with:
I am expecting the result to look like this image: https://ibb.co/SXkTp6m
Any help would be greatly appreciated.
function addDay(e) {
document.getElementById(e.value).style.display = e.checked ? "initial" : "none";
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/ >
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<input type="checkbox" value="lundi" id="lundiCheck" onclick="addDay(this)" />1
<input type="checkbox" value="mardi" id="mardiCheck" onclick="addDay(this)" />2
<input type="checkbox" value="mercredi" id="mercrediCheck" onclick="addDay(this)" />3
<input type="checkbox" value="jeudi" id="jeudiCheck" onclick="addDay(this)" />4
<input type="checkbox" value="vendredi" id="vendrediCheck" onclick="addDay(this)" />5
<input type="checkbox" value="samedi" id="samediCheck" onclick="addDay(this)" />6
<input type="checkbox" value="dimanche" id="dimancheCheck" onclick="addDay(this)" />7
</div>
<div class="container">
<div class="row" style="display:none;" id="lundi">Some content1</div>
<div class="row" style="display:none;" id="mardi">Some content2</div>
<div class="row" style="display:none;" id="mercredi">Some content3</div>
<div class="row" style="display:none;" id="jeudi">Some content4</div>
<div class="row" style="display:none;" id="vendredi">Some content5</div>
<div class="row" style="display:none;" id="samedi">Some content6</div>
<div class="row" style="display:none;" id="dimanche">Some content6</div>
</div>