jeudi 29 mars 2018

How to remove a div containing a checkbox with a specific id?

I have different checkboxes generated dynamically. Each checkboxes are contained within a div.

I would like to do the following action with jquery:

If a checkbox has an id="aucune", then remove its container (the div containing the checkbox with the id="aucune") from the html page.

I tried the following code:

// wait for DOM to be ready
$(document).ready(function() {
  var empty = $("input:checkbox[id=aucune]");
  if (empty == true) {
    $(this).parent().remove();
  }
});

Here is a the very simplified html:

<div class="wrapper-checkbox">
  <input type="checkbox" class="outsider" id="xxx" name="xxx" date-name="xxx">
    <label for="xxx">xxx</label>
</div>

<div class="wrapper-checkbox">
  <input type="checkbox" class="outsider" id="aucune" name="aucune" date-name="aucune">
    <label for="aucune">aucune</label>
</div>

Here is my codepen: I am quite new to code, I apologize for my silly simple question.




Aucun commentaire:

Enregistrer un commentaire