Search code examples
javascriptjqueryclone

problem with cloned field


i have this code that wotks well

now i am trying to change <input id="input1" /> to <div id="input1"> </div> Here.

The problem is the id, it is supposed change, like input1, input2, but in the second example the new divs always have the same id.

In the first example the name of the id's are input1, input2, input3,...


Solution

  • Solved

     $('#btnAdd').click(function() {
            $('.btnDel:disabled').removeAttr('disabled');
            var c = $('.clonedInput:first').clone(true);
                c.children('div').attr('id','input'+ (++inputs) ).val('');
                c.children(':button').attr('name','btnDelete'+ (inputs) );
            $('.clonedInput:last').after(c);
        });