manbearpig1 manbearpig1 - 1 year ago 61
HTML Question

Dynamically append new links to top of list instead of bottom of list

I am dynamically adding links to my list. The newest links are added to the bottom of the list. How would one append each new link to the top of the list?

<ul class="posts" id="posts">
<% for(var i=0; i<posts.length; i++) { %>
<li class="post">
<span><a href="/collab/<%=posts[i]['_id']%>"><%= posts[i].userCreate %></a></span>
<% } %>

Answer Source

If I understand what you are asking correctly you need to iterate your list from the end to the front:

for (var i = posts.length - 1; i >= 0; i--) { 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download