I'm basically trying to move one list item back-and-forth from one unordered list to another, pretty basic stuff. I can click once, so it receives a new class ("squad-btn") and gets rid of his old one ("player-btn") and correctly moves to the other list (squad-list).
Problem is I can't move it back once it has joined this new list. My removal and creation of classes seems fine to me. What's wrong here?
$(document).ready(function() {
$(".player-btn").click(function() {
$(this).appendTo("#squad-list");
$(this).addClass("squad-btn");
$(this).removeClass("player-btn");
});
$(".squad-btn").click(function () {
$(this).appendTo("#player-list");
$(this).addClass("player-btn");
$(this).removeClass("squad-btn");
});
});
And my html file:
<style type="text/css">
#content-box {
width: 400px;
height: 600px;
}
#player-box {
vertical-align: middle;
height: 600px;
width: 200px;
background-color: green;
}
#squad-box {
height: 600px;
width: 200px;
background-color: blue;
}
li {
list-style-type: none;
padding-top: 20px;
}
</style>
<html>
<head>
<link href="https://daneden.github.io/animate.css/animate.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<script type="text/javascript" src="code.js"></script>
<body>
<div class = "container-fluid text-center">
<div align = "center">
<h1>Squad Builder</h1>
<div id = "content-box">
<div id = "player-box" class = "col-md-6">
<ul id = "player-list">
<li class = "player-btn"><button>Messi</button></li>
</ul>
</div>
<div id = "squad-box" class = "col-md-6">
<ul id = "squad-list">
</ul>
</div>
</div>
</div>
</div>
</body>
</html>