Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <p>Select the students that attended class:</p>
  <form method="post" action="/attendance">
    <div class="attendance">
      <div class="attendance__students">
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="James" class="attendance__input" hidden />
          James
        </label>
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="Claire" class="attendance__input" hidden />
          Claire
        </label>
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="Ian" class="attendance__input" hidden />
          Ian
        </label>
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="Darren" class="attendance__input" hidden />
          Darren
        </label>
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="Sophie" class="attendance__input" hidden />
          Sophie
        </label>
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="Ethan" class="attendance__input" hidden />
          Ethan
        </label>
        <label class="attendance__student">
          <input type="checkbox" name="attended" 
                 value="Phoebe" class="attendance__input" hidden />
          Phoebe
        </label>
      </div>
      <div class="attendance__attended"></div>
    </div>
    <button type="submit">Save attendance</button>
  </form>
</body>
</html>
 
[hidden] {
  display: none !important;
}
.attendance {
  display: table;
  width: 100%;
  margin-bottom: 1em;
}
.attendance__students,
.attendance__attended {
  vertical-align: top;
  display: table-cell;
  list-style: none;
  margin: 0;
  padding: 0;
  width: 50%;
}
.attendance__student {
  float: left;
  clear: both;
  padding: 3px;
  border: 1px solid #ddd;
  width: 100px;
  overflow: hidden;
  text-overflow: ellipsisl;
  background-color: #eee;
  margin-bottom: 3px;
  border-radius: 3px;
  cursor: pointer;
}
.attendance__student:hover {
  background-color: #ebf3ff;
}
 
(function($) {
  var selector = '.attendance',
      $students = $(selector + '__students'),
      $attended = $(selector + '__attended');
  
  function init() {
    $(document).on('click', selector + '__input', toggleAttendance);  
  }
  
  function toggleAttendance() {
    var $student = $(this).closest(selector + '__student');
    $student.appendTo(this.checked ? $attended : $students);
  }
  
  $(init);
}(jQuery));
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers