SO - 19803254
by nsjithin
HTML
<div id = "boxes_holder" class = "initBox">
<li><span class = "boxes" style="text-align:center;float:left;margin:10px;" > 1</span></li>
<li><span class = "boxes" style="text-align:center;float:left;margin:10px;" > 2</span></li>
<li><span class = "boxes" style="text-align:center;float:left;margin:10px;" > 3</span></li>
<li><span class = "boxes" style="text-align:center;float:left;margin:10px;" > 4</span></li>
</div>
<div id="dragBox" class = "initBox">
<div id="dragBoxTitle" class = "">
Pick Your Numbers:
</div>
</div>
CSS
.initBox{
width:260px;
height:200px;
border:1px solid #ccc;
display: inline-block;
float: right;
vertical-align:top;
background-color:#FBFBFB;
list-style-type: none;
}
JavaScript
$(document).ready(function () {
$('#boxes_holder, #dragBox').sortable({
connectWith: '.initBox',
update: function( event, ui ) {
$(this).find('li').sort(sortAlpha).appendTo(this);
},
//Whenever Dropped Item
receive: function (event, ui) {
if ($(this).children().length > 4) {
if ($(this).attr('id') == 'dragBox') {
$(ui.sender).sortable('cancel');
}
}
}
});
function sortAlpha(a,b){
return a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase() ? 1 : -1;
}
});