views:

34

answers:

2

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.

+3  A: 

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");
karim79
+3  A: 

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.

Tatu Ulmanen