Hmm, first of all, you should check the LI length in the lists. Or you can make a counter that will go through the list index, and then add a new LI.
var App = { lists: ['#column1', '#column2', '#column3'], index: 0, getList: function () { if (this.index == this.lists.length + 1) { // verifying if it in the last column index this.index = 0; return App.lists[0]; } else { return App.lists[this.index++]; } } }; // global configs $("#myLink").bind('click', function () { var $li = $(App.getList()).append('<li></li>'); $.ajax({ url: 'getLastLalala.php', beforeSend: function () { $li.text('Loading...'); }, success: function (data) { $li.html(data); } }); });
source share