Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <p>HTML:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script data-require="jquery@1.9.1" data-semver="1.9.1" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="style.css" /&gt; &lt;script src="script.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Click me to Sort&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Mission&lt;/li&gt; &lt;li&gt;Vision&lt;/li&gt; &lt;li&gt;Objectives&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>JavaScript: </p> <pre><code>$(function() { $('p').click(function() { var list = $('ul'); var listitems = list.children('li').get(); listitems.sort(function(e1, e2) { return $(e1).text().toUpperCase().localeCompare($(e2).text().toUpperCase()); }) $.each(listitems, function(idx, itm) { list.append(itm); }); }); }); </code></pre> <p>CSS:</p> <pre><code>ul { list-style-type: none; width: 200px; background: #bdbdbd; } </code></pre> <p><a href="http://plnkr.co/edit/u4IITe?p=preview" rel="nofollow">Plunker example</a></p> <p><strong>UPDATE:</strong> (answer for comment) To sort and unsort you should modify JavaScript:</p> <pre><code>$(function() { var noSortedTxts = []; var sortedTxts = []; var sort = true; $('p').click(function() { var list = $('ul'); if (noSortedTxts.length === 0) { var listitems = list.children('li').get(); $.each(listitems, function(idx, itm) { noSortedTxts.push($(itm).text()); }); sortedTxts = noSortedTxts.slice(0); sortedTxts.sort(function(t1, t2) { return t1.toUpperCase().localeCompare(t2.toUpperCase()); }); } if (sort) { list.empty(); $.each(sortedTxts, function(idx, txt) { list.append('&lt;li&gt;' + txt + '&lt;/li&gt;'); }); sort = false; } else { list.empty(); $.each(noSortedTxts, function(idx, txt) { list.append('&lt;li&gt;' + txt + '&lt;/li&gt;'); }); sort = true; } }); }); </code></pre> <p><a href="http://plnkr.co/edit/niDTIo?p=preview" rel="nofollow">Plunker example</a></p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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