jQuery: clone newest row in table -- not last row, newest

I have a form that adds rows to a table upon submit:
Want to add/append to submit function as follows without "disturbing" its existing functionality: $("#scan_form").submit(function() { //clone row and add to hidden table. }); When it adds a row, I'd like it to add that same row to a different hidden table for printing. I'm thinking I need to somehow bind a function to the table that adds this same row to a different table but am stuck. Using the below SO question as a template, how do I capture this newest row? https://stackoverflow.com/questions/9095472/listen-for-added-table-rows $('#table_id').bind('rowAddOrRemove', function(event){ //do what you want. }); The table is sorted alphabetically, so the newest row won't necessarily be the last row. **UPDATE**
Trying this idea: Step 1: Set id of all existing rows to 'oldRow' $( '#loanTable tr' ).attr("id", "oldRow"); Step 2: Clone table above: var lbl = $("#loanTable tbody"); var newLbl = $(lbl[0].outerHTML); Step 3: Delete rows with id 'oldRow' $(".oldRow", newLbl).remove(); As you surmised, it deleted everything. How do I connect these dots? **UPDATE 2**
How do I do the following? $('#table_id').bind('rowAddOrRemove', function(event){ //add attribute print to 'this' row. }); Want to label new rows added to table.
Consider adding a timestamp to the rows (perhaps a data-attribute?) - then it can be used for sorting, or finding and deleting.

以上就是jQuery: clone newest row in table -- not last row, newest的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准