I am using simple Jquery sortable that user can drag and drop element, but on every element i have some number, on loading screen all numbers are in order, but what i need whabe someone reoders element to auto chnage that number according to his selection. Here is working fiddle what i have
I need when someone move etc. Number 10 to be the first to chnage that number to 1 and all others to reindex?
Here is code for now
<ol class="example">
<li> <span>1</span>
<ol></ol>
</li>
<li> <span>2</span>
<ol></ol>
</li>
<li> <span>3</span>
<ol>
<li><span>4</span>
</li>
<li><span>5</span>
</li>
<li> <span>6</span>
<ol>
<li><span>7</span>
</li>
</ol>
<ol>
<li><span>8</span>
</li>
<li><span>9</span>
</li>
</ol>
</li>
</ol>
</li>
<li><span>10</span>
</li>
</ol>
JS
$(function () {
$("ol.example").sortable()
})
UPDATE
Now i have structure like this 1, 2, 3, 4, 5 etc.
What i need when someone move 4 to first place to chnage that number to 1 and all other numbers to reorder, like I move number 4 to first place it chnage number to 1, and first that is under new 1 to chnage that number to 2 and further