4

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.

1
  • This is a very broad question. The answer will depend on how is your server script sending the data. Is it using JSON, XML, partial HTML or is it something else? Commented Feb 17, 2010 at 10:51

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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");

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.