How to replace a table with a new one using jQuery?

What is the best way to replace <table> with a new one using jQuery? I use ajax on the page to get new data.

+4
source share
2 answers

If you don't want to add a shell element, something like this should work:

 $.ajax({ url: 'yoururl.php', success: function(r) { $('table#something').replaceWith(r); } }); 

.. assuming the answer you received is an element of a table.

+4
source

Wrap it in a div and:

 $("#myDiv").load("/some/url.php"); // where url.php outputs the entire table 

You can specify the part of the remote document to be inserted by placing it in the selector with the URL parameter as follows:

 $("#myDiv").load("/some/url.php #myTable"); 
+3
source

Source: https://habr.com/ru/post/1301562/


All Articles