I am working on a page that has a form that puts data into one table, and also a list of items that come from that table.
I want to show the newest items on top of the list after the form is added.
Rigth now, the form makes an AJAX call, I get the data, send it back to jQuery in case of success, than I loop through the data.
But here I am confused about how to display the data. If I use the append function, it will append to the bottom (I need it to go on top of the list). If I completely replace the list and repopulate it, is that the better solution? Seems heavy-handed.
What is the best pattern here to accomplish what I am trying to do?
jQuery has a
prepend()function which is essentially the opposite ofappend(); rather than adding to the bottom, it adds to the top. From the information you’ve given that should work for your particular use.