Eugene Yarmash
Eugene Yarmash

Reputation: 149736

How can I replace a table with a new one using jQuery?

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

Answers (2)

Tatu Ulmanen
Tatu Ulmanen

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

karim79
karim79

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

Related Questions