Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is the number before each item strictly based on position? </p> <p>If so, once the sort is complete you could just replace the content based on each li element.</p> <p>Does it matter how the URL contains the list text? </p> <p>In the below I operated with the assumption that it can all be appended with a querystring value of list.</p> <p>There are shorter ways to do this, but hopefully the verbosity will aid in understanding what happens.</p> <pre><code>&lt;script&gt; var listChanger = function() { //updates the digits prepended to each item in list //updates URL with text of list in querystring //accumulates the text of each list item var valueAccumulator = []; //Operate of each item in myList $('#myList li').each(function(index) { //regular expression to strip initial digits var reInitialDigits = /^\d+/; //remove initial digits var textWithoutDigits = $(this).text().replace(reInitialDigits,""); //prepend new digits (index starts at 0, so add 1 then multiply by 10 to get desired number) $(this).text(((index + 1) * 10) + textWithoutDigits); //append text to accumulator valueAccumulator.push($(this).text()); }); //querystring to strip everything after the querystring var reQueryString = /\?list\=.*$/; //placeholder var linkWithoutQueryString = ''; //remove querystring linkWithoutQueryString = $('#myLink').attr('href').replace(reQueryString,''); //change link to include URL encoded list of values $('#myLink').attr('href',linkWithoutQueryString + "?list=" + encodeURI(valueAccumulator.join("|"))); } $(document).ready(function() { //make the list sortable and each time the sorting stops, run the listChanger function $("#myList").sortable({stop:listChanger}); }); &lt;/script&gt; &lt;ul id="myList"&gt; &lt;li&gt;10 Apple &lt;/li&gt; &lt;li&gt;20 Banana &lt;/li&gt; &lt;li&gt;30 Orange &lt;/li&gt; &lt;/ul&gt; &lt;br /&gt; &lt;a id="myLink" href="mylink.html"&gt;mylink.html&lt;/a&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload