10

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});
1
  • the button that is clicked to call the function containing the jquery. Commented Nov 2, 2011 at 17:50

2 Answers 2

16

You need something like this instead:

$.get('@Url.Action("TaskRow", "Task")', {'id': id}, function(data) {
    $(elem).closest('table').find('tr.tasks').replaceWith(data);
});
Sign up to request clarification or add additional context in comments.

2 Comments

yeh i thought something like that might be the answer. But if so, how would i assign the .load(.. part of my code to the data variable? It has to be chained to something right, the .load() function?
You want to replace a table row, so .load isn't what you need. By using $.get you can employ a callback function that adds the data to the DOM however you like.
15
var newRow = '<tr><td>blahh blah</td><td>blah...</td></tr>';
$('#tempID').replaceWith(newRow);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.