Closed seristee closed 8 years ago
add .first() to the end of your selector, like this:
$('#clonedForm').triggerHandler('clone.cloneya',[$('.toclone').first()]);
or better yet, use last() to clone the last clone
$('#clonedForm').triggerHandler('clone.cloneya',[$('.toclone').last()]);
In these lines:
$('.customButton').on('click', function(){
$('#clonedForm').triggerHandler('clone.cloneya',[$('.toclone')]);
});
you have basically asked to clone all the clonable elements (all elements with class .toclone
). As @solarsilk has pointed, you'd have to specify the one that you want cloned. Otherwise, if you click the clone button once, you'd get one copy (total 2).
click button again, you'd get 2 X 2 = 4 copies, then 8, then 16. It'd be a nightmare. So, you either use the .first()
or .last()
modifiers for your selector or use another way to specify which particular .toclone
needs to be cloned.
I am having an issue with using the plugins custom clone button. What happens is every time i click the clone button i get double the clones. here is my code. any help would be greatly appreciated. How do i get this rectified as I am new to javascript.