Jquery events not binding to newly cloned fields

I have a form that allows the user to add more fields. I do this by cloning the div that they are in. I do use clone(true) but the problem I am having is that the jquery I use to ensure numeric input doesn't seem to work on the newly cloned fields. When I type in them they change the values in the top set of fields(the one that was cloned) This is my clone function

$('#more_fields').click(function(){
        if(fields >= 5)
        {
            alert("We're Sorry... You can have a maximum of 6 fieldsets for a freightquote request");
        }
        else
        {
            $('.freight_fields:first').clone(true).hide().insertAfter('.freight_fields:last').slideDown('slow');
                var last = $('.freight_fields:last');
                last.append(new_button.clone(true));
                fields++;
        }
        }); 

And I am using the autonumeric library with the class numbers_only on these fields like this

$('.numbers_only').autoNumeric({mDec:0});

If any of that was confusing ... when I clone freight_fields (the outer div) which contains field_one and I type in the cloned version of field_one the value in the original is changed and the new one doesn't change. I'm sure it has something to do with the fact that the true I pass only affects the outer div, but there are a lot of fields in this thing and I don't want to have to clone each of them individually in order to bind them.

Answers


It is generally unsafe to clone an element that had plugins applied on to inherit the plugins features, unless you know that the plugin was applied to the element in a clone-friendly way.

I strongly advise you to simply clone the element using clone(false) and then reapply the plugin on cloned elements.


Need Your Help

C# NAudio - Changing audio playback position still plays a small buffer of old position

c# wpf position mp3 naudio

I am trying to make a basic MP3 player in C# and WPF, along with NAudio. I recently added a slider that tracks the current position in the song as well as allows you to drag it to a different posit...

For loop in R starting from other value

r loops

This has been bothering me for some time now. Imagine you have to/want to use a loop.