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

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.30 KB  |  hits: 8  |  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. JQuery erratic behavior of cloned links
  2. <div class="pages"></div>
  3.  
  4. <div id="workspace"><br/></div>
  5.  
  6. <div id="pagesclone"></div>
  7.        
  8. //Generate page number links
  9. for (x = 1; x < 6; x++) {
  10.     $('.pages').append(' <a href="#" class="links">' + x + '</a> ');    
  11. }
  12.  
  13. page = 1;
  14.  
  15. //Function for link clicks
  16. $('.links').click(function() {
  17.     //"You clicked .."
  18.    current = $(this).html();
  19.    $('#workspace').html('You clicked ' + current);
  20.  
  21.     //shifting the active page    
  22.    $('.links').slice(page - 1, page).attr('href', '#'); //activate preceeding link
  23.    page = $(this).html(); //reset page number to the link clicked
  24.    $('.links').slice(page - 1, page).removeAttr('href'); //remove href attribute
  25. });
  26.  
  27.  
  28. //Clone the top row of links to the bottom
  29. $('.pages').clone(true, true).appendTo('#pagesclone');
  30.        
  31. $('.pages').append(' <a href="#" class="links link-' + x + '">' + x + '</a> ');
  32.        
  33. $('.links.link-' + page).attr('href', '#'); //activate preceeding link
  34. page = $(this).html(); //set page number to the link clicked
  35. $('.links.link-' + page).removeAttr('href'); //remove href attribute
  36.        
  37. var link = [1, 2, 3, 4, 5];
  38.  
  39. $.each(link, function(a) {
  40.     $(".pages").append("<a href='#' class='a" + a + "'>" + link[a] + "</a>");
  41. });
  42.  
  43. $("a").click(function() {
  44.     $("." + $(this).attr('class')).removeAttr("href");
  45. });​