Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how do i get the last element of a $.each
  2. $.each(data, function (url) {
  3.       $("ul").append($("<li class='horizontal'></li>").html(this.title));
  4.     });
  5.        
  6. $.each(data, function(i,v){
  7.   $('<li />').html(v.title).appendTo('ul');
  8. });
  9. $('ul li:last').addClass('horizontal');
  10.        
  11. $("#theUl li:last").addClass("horizontal"); // or $("ul:last"), whichever you mean
  12.        
  13. var lis = '';
  14. $.each(data, function (url) {
  15.     lis += "<li>" + this.title + "</li>";
  16. });
  17. $("ul").append(lis);
  18. $("ul li:last").addClass("horizontal");
  19.        
  20. data.length
  21.        
  22. $.each(data, function (url) {
  23.   $("ul").append($("<li class='horizontal'></li>").html(this.title));
  24. });
  25.  
  26. $("ul li:last").addClass("last");