Reputation: 149736
Whats the best way to replace a <table>
with a new one using jQuery? I'm using ajax on the page to get the new data.
Upvotes: 4
Views: 581
Reputation: 124768
If you don't want to add a wrapper element, something like this should work:
$.ajax({
url: 'yoururl.php',
success: function(r) {
$('table#something').replaceWith(r);
}
});
..assuming the response you get is an table element.
Upvotes: 4
Reputation: 342635
Wrap it in a div, and:
$("#myDiv").load("/some/url.php"); // where url.php outputs the entire table
You can specify a portion of the remote document to insert by putting it's selector with the URL parameter as follows:
$("#myDiv").load("/some/url.php #myTable");
Upvotes: 3