Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Test Page</title>
<style>
  body {
    font-family: sans-serif;
  }
  #members div {
    height: 1em;
    border: 1px solid black;
  }
</style>
</head>
<body>
<label><input type='checkbox' name='check[]' id='x159' value='159' />
  Person 1</label>
<label>
  <input type='checkbox' name='check[]' id='x160' value='160' />Person 2</label>
<div id="members"></div>
</body>
</html>
 
    $(function(){
        $('input:checkbox').click(function(){
            var id  = this.id; // No need for `attr`
            
            if(this.checked){  // No need for `attr`
                $("<div>")
                    .html('<a href="#">'+$(this.parentNode).text()+'</a>')
                    .attr("data-contents", id)
                    .appendTo("#members");
            }
            else {
                $('div[data-contents="' + id + '"]').remove();
            }
        });
    });
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers