One of my APP dev requires
I clone a link 3 times and stored in to an object. after i stored to object i have added some click event to stored object's link element.
I have a navigation link, when user click on the navi number, i am appending the stored element to container.
All it works. the issue is:
the click event of the link only works on page load. it's not working after shuffling the other stored object to container.
how to fix this. the event all are goes away. click event not working further.
here is my js:
var listLength = $('li').length;
var origional = $('.content');
var catcheEl = {};
for(i=1;i<= listLength;i++){
catcheEl['content'+i] = origional.clone();
var link = $(catcheEl['content'+i]).find('a').addClass('link'+i);
addEvent(link);
}
function addEvent (link) {
var x = 0;
link.click(function(e){
e.preventDefault();
x++;
console.log(x);
$(this).addClass('p'+x); //only adds on page load.
});
}
$('li').click(function(){
var num = $(this).find('button').prop('class');
$('#newContainer').html(catcheEl['content'+num]); //not working once other elements loaded.
});
$('.content').hide();
What i require is :
I should shuffle the
linkelement clicking the navi buttonthe class name of
elementshould continuethe added event should be continue.
Thanks in Advance.
addEvent