JSFiddle - React, Tailwind, and code Playground

by techiedelight

HTML

<!doctype html>
<html>
  <body>
    <p>Choose your vechicle:</p>
    <div>
      <input type="checkbox" id="bike" name="vechicle" value="bike" checked>
      <label for="bike">Bike</label>
    </div>
     <div>
      <input type="checkbox" id="scooter" name="vechicle" value="scooter" checked>
      <label for="scooter">Scooter</label>
    </div>
    <div>
      <input type="checkbox" id="car" name="vechicle" value="car">
      <label for="car">Car</label>
    </div>
    <div>
      <input type="checkbox" id="auto" name="vechicle" value="auto">
      <label for="auto">Auto</label>
    </div>
    <div>
      <button id="select">Get Checked Checkboxes</button>
    </div>
    <br>
  </body>
</html>

CSS

p, label {
    font: 15px 'Exo 2', sans-serif;
}

input {
    margin: 6px;
}

button {
  margin-top: 10px;
  padding: 2 2;
  font: 15px 'Exo 2', sans-serif;
}

JavaScript

$(document).ready(function() {
  $('#select').click(function() {
    var values = $('input[type="checkbox"]:checked').map(function() {
      return $(this).val();
    }).get().join(',');

    document.body.append(values);
  })
});