I have a a and I would like to sort my list alphabetically (I don’t want caps to matter) according to a class named “name”. How would I do this?
<ul class="column">
<li>
<table>
<tr>
<td class="name" >Name of Item</td>
</tr>
<tr>
<td>Content</td>
</tr>
<tr>
<td>morecontent</td>
<td>morecontent</td>
</tr>
</table>
</li>
<li>
<table>
<tr>
<td class="name" >Another name of item</td>
</tr>
<tr>
<td>Content</td>
</tr>
<tr>
<td>morecontent</td>
<td>morecontent</td>
</tr>
</table>
</li>
</ul>
Thanks
Using jQuery, this should do it:
The above is a little dense though, so if you want to understand what’s going on, let’s break it down line-by-line:
We can make it a little more reusable by passing in the selector for the list and the key:
Do keep in mind this requires jQuery, so you’ll need a reference to it in your
<head>:And this function should be called at some point in the page after the list is written in the HTML.