Posted By

smashu on 04/22/10


Tagged

list jquery split colums


Versions (?)

jquery split list in 2 columns


 / Published in: JavaScript
 

  1. var splitList = function(listClass) {
  2. var originalList = $(listClass);
  3. var originalItems = originalList.children();
  4. var splitAt = Math.round(originalItems.length/2);
  5.  
  6. //clone it but hide it
  7. var cloneList = originalList.clone().insertAfter(originalList).css('display','none');
  8. var clonedItems = cloneList.children();
  9.  
  10. //remove first half of LIs from clone list
  11. for (var i=0; i<clonedItems.length; i++) {
  12. if(i < splitAt) {
  13. $(clonedItems[i]).remove();
  14. }
  15. }
  16. //remove last half of LIs from original list
  17. for (var i=0; i<originalItems.length; i++) {
  18. if(i >= splitAt) {
  19. $(originalItems[i]).remove();
  20. }
  21. }
  22. //show it
  23. cloneList.css('display','block');
  24. }

Report this snippet  

You need to login to post a comment.