views:

29

answers:

1

Could you please tell me how to copy events, if I copy some html? I have a function to copy:

function add_to_order( row, row_input_value ) {



  $('#buffer').html( row ).find('td:first').remove(); // add row to buffer and remove the first td element

   $('#buffer').append('<td class="delete"><span class="remove-from-order button minus" ></span></td>').html(); // append minus

   var row_clear = $('#buffer').html();

   $.post('core/ajax.linker.php',
  {action: 'add_to_sess', data: row_clear}
   );

   $('.items').append('<tr class="fresh">'+row_clear+'</tr>').find('input.add-amt:last').val(row_input_value); // highlight new

   $('.fresh > td > .add-key').attr("class", '');
   $('.fresh > td > .add-value').attr("class", '');
   count_sum();
    }

And a function, that should work after the previous copied html:

    $('input.add-amt').keyup( function () {
       var amt = $(this).val();
       count_sum();
    });

In fact, the first one copies the textfield, and the second have to get the value of that field, but it doesn't.

Any help will be appreciated

+1  A: 

You should take a look at jQuery's clone-function. It duplicates all selected nodes instead of their string representation.

elusive
And if I make two copy operations (source-buffer, buffer-destination) i should use .clone() twice?
M2_
No, you only need one `clone()`-operation. You store the cloned element in your buffer. Since this is already a copy of the source-elements, you do not need to copy them a second time.
elusive