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>
  <div class="attendance">
    <ul class="attendance__students">
      <li class="attendance__student">James</li>
      <li class="attendance__student">Claire</li>
      <li class="attendance__student">Ian</li>
      <li class="attendance__student">Darren</li>
      <li class="attendance__student">Sophie</li>
      <li class="attendance__student">Ethan</li>
      <li class="attendance__student">Phoebe</li>
    </ul>
    <ul class="attendance__attended">
    </ul>
  </div>
</body>
</html>
 
.attendance {
  display: table;
  width: 100%;
}
.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 + '__student', toggleAttendance);  
  }
  
  function toggleAttendance() {
    var $student = $(this),
        isSelected = !!$student.closest($attended).length;
    $student.appendTo(isSelected ? $students : $attended);
  }
  
  $(init);
}(jQuery));
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers