
Untitled
By: a guest on
Jul 15th, 2012 | syntax:
None | size: 1.30 KB | hits: 8 | expires: Never
JQuery erratic behavior of cloned links
<div class="pages"></div>
<div id="workspace"><br/></div>
<div id="pagesclone"></div>
//Generate page number links
for (x = 1; x < 6; x++) {
$('.pages').append(' <a href="#" class="links">' + x + '</a> ');
}
page = 1;
//Function for link clicks
$('.links').click(function() {
//"You clicked .."
current = $(this).html();
$('#workspace').html('You clicked ' + current);
//shifting the active page
$('.links').slice(page - 1, page).attr('href', '#'); //activate preceeding link
page = $(this).html(); //reset page number to the link clicked
$('.links').slice(page - 1, page).removeAttr('href'); //remove href attribute
});
//Clone the top row of links to the bottom
$('.pages').clone(true, true).appendTo('#pagesclone');
$('.pages').append(' <a href="#" class="links link-' + x + '">' + x + '</a> ');
$('.links.link-' + page).attr('href', '#'); //activate preceeding link
page = $(this).html(); //set page number to the link clicked
$('.links.link-' + page).removeAttr('href'); //remove href attribute
var link = [1, 2, 3, 4, 5];
$.each(link, function(a) {
$(".pages").append("<a href='#' class='a" + a + "'>" + link[a] + "</a>");
});
$("a").click(function() {
$("." + $(this).attr('class')).removeAttr("href");
});