Arminas Bekampis Arminas Bekampis - 3 months ago 11
HTML Question

Is it possible to don't trigger checkbox when clicked on its label?

Basically what I wan't to do is to make jQuery function that when it is clicked on the checkbox name I have prompt window to change checkbox name, but it is automatically check/uncheck checkbox itself. I need that Is it possible to don't trigger checkbox when clicked on its label?

P.S Hope it clear what i wrote :)

My markup is:

<div class="checkbox">
<input id="check1" type="checkbox" name="check">
<label for="check1">Checklist One</label>
<br>
<input id="check2" type="checkbox" name="check" checked>
<label for="check2">Checklist two</label>
<br>
<input id="check3" type="checkbox" name="check">
<label for="check3">Checklist 3</label>
</div> <!-- END OF CHECKBOX -->

Answer

You can solve it like this:

$('label').on('click', function(e){
  e.preventDefault();
  
  // here you can add your code to handle the rename
})
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</head>
<body>
<div class="checkbox">
  <input id="check1" type="checkbox" name="check">
  <label for="check1">Checklist One</label>
  <br>
  <input id="check2" type="checkbox" name="check" checked>
  <label for="check2">Checklist two</label>
  <br>
  <input id="check3" type="checkbox" name="check">
  <label for="check3">Checklist 3</label>
</div>
</body>
</html>