Guest User

Untitled

a guest
Mar 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <button id='add' for-table='#example1'>Add Row</button>
  2.  
  3. $("#add").click(function(e){
  4. var table = $(this).attr('for-table'); //get the target table selector
  5. var $tr = $(table + ">tbody>tr:last-child").clone(true, true); //clone the last row
  6. var nextID = parseInt($tr.find("input.tabledit-identifier").val()) + 1; //get the ID and add one.
  7. $tr.find("input.tabledit-identifier").val(nextID); //set the row identifier
  8. $tr.find("span.tabledit-identifier").text(nextID); //set the row identifier
  9. $(table + ">tbody").append($tr); //add the row to the table
  10. $tr.find(".tabledit-edit-button").click(); //pretend to click the edit button
  11. $tr.find("input, select").val(""); //wipe out the inputs.
  12. });
Add Comment
Please, Sign In to add comment