Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Replace table row in JQuery

I have a partial view "taskrow" that will return a table row, I am using this to show rows in tables as soon as they have been updated. I need to replace the row with class "tasks" and replace it with the row that is loaded, but am struggling with the syntax. I believe the code below is inserting a tr into a tr. I have tried for ages to use a combination of replaceWith and load() but have not managed to get this working. Could someone help me with this?

$(elem).parent().find("tr.tasks").load("@Url.Action("TaskRow", "Task")", { "id": id});
like image 805
DevDave Avatar asked Nov 02 '11 17:11

DevDave


2 Answers

You need something like this instead:

$.get('@Url.Action("TaskRow", "Task")', {'id': id}, function(data) {
    $(elem).closest('table').find('tr.tasks').replaceWith(data);
});
like image 145
Blazemonger Avatar answered Nov 06 '22 01:11

Blazemonger


var newRow = '<tr><td>blahh blah</td><td>blah...</td></tr>';
$('#tempID').replaceWith(newRow);
like image 14
Ram Vangala Avatar answered Nov 06 '22 01:11

Ram Vangala