bantikyan / icheck-bootstrap

Pure css checkboxes and radio buttons for Twitter Bootstrap.
https://bantikyan.github.io/icheck-bootstrap/
MIT License
141 stars 35 forks source link

Stylessheet failed for group of checkboxes having same ID #8

Closed satshil closed 5 years ago

satshil commented 5 years ago

Adding a group of checkboxes with same id results in stylesheel failure to recognize which checkbox it belongs to.

e.g.

<div>
    <div>Select countries from europe</div><br>
              <div class="">
                  <div class="icheck-primary">
                    <input id="countries" value="france" type="checkbox" checked>
                    <label>France</label>
                  </div>
                  <div class="icheck-primary">
                    <input id="countries" value="greece" type="checkbox">
                    <label>Greece</label>
                  </div>
                  <div class="icheck-primary d-inline">
                    <input id="countries" value="china" type="checkbox">
                    <label>china</label>
                  </div>
                </div>
<div>
bantikyan commented 5 years ago

Having multiple elements with same id on the same page is not correct. The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

Please improve your code to have valid html (unique id for each element). Also it is important to have for attribute for label to use icheck-bootstrap. You can see example in documentation:

<div class="icheck-primary">
    <input type="checkbox" id="someCheckboxId" />
    <label for="someCheckboxId">Click to check</label>
</div>