I'm trying to get an unordered list to show its items in a reversed order. In other words, getting this:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
To show:
- Three
- Two
- One
I tried jQuery with this answer: jQuery reversing the order of child elements
However, it didn't work for me for some reason. (I put it in a .html file, and also I tried using <script src="script.js"></script>
)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
var list = $('ul');
var listItems = list.children('li');
list.append(listItems.get().reverse());
</script>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
Additionally, that answer was from 4 years ago, so I'm wondering if there's now a better solution?