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-1.10.2.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <select size="10" multiple>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
    <option value="5">Five</option>
    <option value="6">Six</option>
    <option value="7">Seven</option>
    <option value="8">Eight</option>
    <option value="9">Nine</option>
  </select>
  <script>
    (function() {
      var selected = {};
      $('select').click(function(e) {
        var $this = $(this),
            options = this.options,
            option,
            value,
            n;
        
        // Find out what option was just added
        value = $this.val();
        
        // Re-apply the selections
        for (n = 0; n < options.length; ++n) {
          option = options[n];
          if (option.value == value) {
            // The one being updated
            selected[value] = !selected[value];
          }
          // One of the others
          option.selected = !!selected[option.value];
        }
        
        return false;
      });
    })();
  </script>
</body>
</html>
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers