-1

I did show/hide on the checkbox when I check BUTTON appear and when I uncheck BUTTON disappear, I am trying when I hide BUTTON then checkbox should uncheck

$(".btn-close").hide();

$(".btn-close").click(function() {
  $(this).hide();
});

$(function() {
  $("#fileTypeS1").click(function() {
    if ($(this).is(":checked")) {
      $(".btn-close.image").show();
    } else {
      $(".btn-close.image").hide();
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" name="freeAsset" value="valuable" id="fileTypeS1"><br>
<button type="button" class="btn-close image" aria-label="Close">
  Images <span aria-hidden="true">×</span>
</button>

Fiddle Demo

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Adam Pavlov
  • 307
  • 4
  • 17
  • You appear to be attempting to run some jQuery code outside of a document.ready handler. That needs to be moved inside. Alternatively, if all of this code is contained within a document.ready handler which you didn't include here, then you should remove the one around the `#fileTypeS1` click handler. – Rory McCrossan Oct 25 '18 at 08:23

1 Answers1

1

Change close button function to

$(".btn-close").click(function(){
  $(this).hide();
   $("#fileTypeS1").prop('checked', false);
});
Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
Sooriya Dasanayake
  • 1,106
  • 1
  • 7
  • 14