I have a list here I want to short according to DESC order. like 10,9,8,7,6,5,4,3,2,1 I am targetting data-id to change. but here it's starting from lowest value. I want to start from upper value
jQuery('.photos').sortable({
stop: function(event, ui){
let myIncrementor = GetLowestDataIdValue(); //Custom value returned from function
$(".ui-sortable li").each(function(i, el){
$(el).attr('data-id',myIncrementor);
myIncrementor += 1; //increment it
});
}
});
function GetLowestDataIdValue(ui){
let lowestVal = -1;
$('.photos.ui-sortable').find('li').each(function(i, el){
if(parseInt($(el).attr('data-id')) < lowestVal || lowestVal === -1){
// alert(lowestVal);
lowestVal = parseInt($(el).attr('data-id'));
}
});
return lowestVal;
}
#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; cursor:move; }
#sortable li span { position: absolute; margin-left: -1.3em; }
#sortable li.fixed{cursor:default; color:#959595; opacity:0.5;}
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<ul class="photos ui-sortable">
<li class="photo" data-id="21">pawal</li>
<li class="photo" data-id="22">sigma</li>
<li class="photo" data-id="23">notea</li>
<li class="photo" data-id="24">missouri</li>
<li class="photo" data-id="25">Ooops</li>
<li class="photo" data-id="26">Ratee</li>
</ul>