jquery - Clone an element on document.ready, only stored in variable for first action -
i trying clone div , store in variable on page load, , append everytime button clicked. works when click button first time. idea why is?
$(document).ready(function() { var inquiryitem; inquiryitem = $('.firstitem').clone(); $('body').on('click', '.create-inquiry-add', function() { $(inquiryitem).addclass('animated fadein newitem').removeclass('firstitem').insertafter('.inquiry-item:last-child'); }); });
you cloning once using append()
method move same element (to same place guess). code should be:
$(document).ready(function () { var $inquiryitem = $('.firstitem'); $('body').on('click', '.create-inquiry-add', function () { $inquiryitem.clone().toggleclass('animated fadein newitem firstitem').insertafter('.inquiry-item:last-child'); }); });
using toggleclass()
simplicity if former element hasn't animated fadein newitem
classes set default.
Comments
Post a Comment