jQuery clone inputs and selects not working

Posted on November 24, 2014 in Web Dev

Use clone(true) to attach handlers to all new inputs. Kinda like updating the DOM.

$('.add-new-office').click(function(event) {
    event.preventDefault();
    $(this).closest('.additional-offices-container').clone(true).appendTo('.multiple-offices-container');
});

 

If you don’t do this, your cloned selectors won’t have any JS handlers attached to them and will for all intents and purposes not be contained within the DOM.

Leave a comment

Was this helpful? Did I miss something? Do you have a question? Get in touch, or tell me below.