mardi 15 août 2017

Jquery/JS Show dynamic checkbox input group title if at least one or more are checked and vice versa

I want to show input group title if at least one checkbox is checked, and hide title if no checkboxes checked. Each group has his own title and data-value. There may be 5+ input groups.

Here is the codepen: [Example code here][1]


[1]: http://ift.tt/2uXI2lg

$(document).ready(function(){
  
});
.output {
  margin-top:45px;
}
<div class="group-block" data-value="1">
  <h1 class="group-title" data-value="1">group1</h1>
  <input type="checkbox" data-value="1">item1
  <input type="checkbox" data-value="1">item2
  <input type="checkbox" data-value="1">item3
  <input type="checkbox" data-value="1">item4
</div>

<div class="group-block" data-value="2">
  <h1 class="group-title" data-value="2">group2</h1>
  <input type="checkbox" data-value="2">item1
  <input type="checkbox" data-value="2">item2
  <input type="checkbox" data-value="2">item3
  <input type="checkbox" data-value="2">item4
</div>

<div class="output">HERE SHOW TITLES</div>
  <script src="http://ift.tt/1oMJErh"></script>

enter code here

At the end, I'm not so good with JS/Jquery but I was trying to make it work for a few hours and have a feeling that I go very deep but there is a 2 line solution.

Thanks for help




Aucun commentaire:

Enregistrer un commentaire