I don't have any trouble grabbing a list of elements and sorting them alphabetically, but I'm having difficulty understanding how to do it with a modulus.
### UPDATE ###
Here's the code working 'my way', however, I like the re-usability of the answer provided below more, so have accepted that answer.
<script type="text/javascript">
$(document).ready( function() {
$('.sectionList2').each( function() {
var oldList = $('li a', this),
columns = 4,
newList = [];
for( var start = 0; start < columns; start++){
for( var i = start; i < oldList.length; i += columns){
newList.push('<li><a href="' + oldList[i].href + '">' + $(oldList[i]).text() + '</a></li>');
}
}
$(this).html(newList.join(''));
});
});
</script>
For example. Say I have the following unordered list:
<ul>
<li><a href="~">Boots</a></li>
<li><a href="~">Eyewear</a></li>
<li><a href="~">Gloves</a></li>
<li><a href="~">Heated Gear</a></li>
<li><a href="~">Helmet Accessories</a></li>
<li><a href="~">Helmets</a></li>
<li><a href="~">Jackets</a></li>
<li><a href="~">Mechanic's Wear</a></li>
<li><a href="~">Pants</a></li>
<li><a href="~">Protection</a></li>
<li><a href="~">Rainwear</a></li>
<li><a href="~">Random Apparel</a></li>
<li><a href="~">Riding Suits</a></li>
<li><a href="~">Riding Underwear</a></li>
<li><a href="~">Socks</a></li>
<li><a href="~">Vests</a></li>
</ul>
I have this list set to display in 4 columns with each li floated right. Visually this makes finding items in larger lists difficult. The output I need is this:
<ul>
<li><a href="~">Boots</a></li>
<li><a href="~">Helmet Accessories</a></li>
<li><a href="~">Pants</a></li>
<li><a href="~">Riding Suits</a></li>
<li><a href="~">Eyewear</a></li>
<li><a href="~">Helmets</a></li>
<li><a href="~">Protection</a></li>
<li><a href="~">Riding Underwear</a></li>
<li><a href="~">Gloves</a></li>
<li><a href="~">Jackets</a></li>
<li><a href="~">Rainwear</a></li>
<li><a href="~">Socks</a></li>
<li><a href="~">Heated Gear</a></li>
<li><a href="~">Mechanic's Wear</a></li>
<li><a href="~">Random Apparel</a></li>
<li><a href="~">Vests</a></li>
</ul>
What I'm looking for is a function that I can pass my array of list items and get my array returned, sorted alphabetically, with a modulus of choice; in this case 4.
Any help would be appreciated as I can find no documentation on the subject.