I have a list which makes use of Jquery UI Sortable. Each list item has a special data-itemid value which is a unique number. User can add items to this list and then sort them. I want to find the max value of the data-itemid attribute regardless of their position in the list.
Before I had implemented Sortable, I could just fetch the value of last-child using $('li:last-child').data('itemid')
but after integrating the sorting functionality, the last child might not have the maximum value.
My code is as follows:
HTML
<ul id='sortable'>
<li data-itemid='1'>One</li>
<li data-itemid='2'>Two</li>
</ul>
Javascript
$(document).ready(function(){
maxItemId = $('li:last-child').data('itemid');
alert('Max Item Id is: ' + maxItemId);
});
I figured I could just go through each li item and look for the one with the max Id, I was hoping there was a better alternative to it.