javascript - Adding "Edit" button with jQuery .append -
i building application allow adding tasks list, , want add edit button, allow user edit each item list , save or delete amended item. want .append code attach "edit" button each row.
here current .append code
var id_counter = 0; if ( valid ) {function increment(){id_counter++;} increment(); var $task = $("<div class='tasklist' id='"+ id_counter +"'><ul class='taskscreen2'><tr>" + "<td><h1>" + type.val() + "</h1></td>" + "<td class='title'><h3>" + title.val() + "</h3></td>" + "<td>" + wordcount.val() + "</td>" + "<td><p>" + description.val() + "</p></td>" + "<td>" + deadline.val() + "</td>" +"<td><button onclick='edit("+id_counter+")'>"+"edit"+"</button></td>" + "</tr></ul></div>" ).appendto("#tasks2 tbody");
i don't know if understood question properly, think should like.
if ( valid ) { var $task = $("<tr class='tasklist'>" + "<td><h1>" + type.val() + "</h1></td>" + "<td class='title'><h3>" + title.val() + "</h3></td>" + "<td>" + wordcount.val() + "</td>" + "<td><p>" + description.val() + "</p></td>" + "<td>" + deadline.val() + "</td>" //new button + "<td><button onclick='edit()'>"+ "edit" + "</button></td>" + "</tr>" ).appendto("#tasks2 tbody");
if want act differently depending on row, call edit function parameter. e.g edit(row_id)
edit
var id_counter var $task = $("<tr class='tasklist' id='"+ id_counter +"'>"
for addition of id in code and
+"<td><button onclick='edit("+id_counter+")'>"+"edit"+"</button></td>"
for button code
you start id_counter = 0;
, add plus 1 each time
Comments
Post a Comment