hello i am new here and i hope i don`t post in a wrong place the problem is like this: i use a .getJson to retrive results from a database. and the results are appendet to a table [multiple rows] once i click to a img it loads a detailed view of the data into a div(or another table). my problem is the following: i must remove the old content of the detailed div - only the appendTo part -
the code looks somethink like this:
script:
$("button.#results").click(
function(){
$.getJSON(dataretrive.php?callback=?&query=1' ,
function(data) {
$.each(data, function(i, item) {
var mindata = "<tr><td class='border'>" +data[i].name+ "</td>";
.... [minimal data]
$(mindata).appendTo("table.#shorttableinfo");
var detailfull = "<tr valign='top' height='25' width='100px'><td> Name: </td><td>" + data[i].name + "</td></tr>"
... [lots of data]
$("img.#editrow" + i ).click(
function(){
$(detailfull).appendTo("table.#detailsfull");
});
});
});
});
the html:
[html code]
<table id="shorttableinfo"> // i need a small table here
<tr><td>Name:</td><td> [other minimal data] </td></tr>
</table>
[other html code]
<table id="detailsfull"> // i need a small table here
<tr><td>Name:</td><td> [other minimal data] </td></tr>
</table>
my problem is that i need the code to be removed before jquery loads the new data into the tablbe with id detailsfull, without removing the first row of the table.
Your selector is invalid on appendTo(), should be appendTo("table#shorttableinfo")
You can remove your rows via
$('table#detailsFull tr:gt(0)').remove();
The above will remove all rows but the first one out of your detailsFull table
Give the things you added a specific class:
var detailfull = "<tr class=specific-data valign='top' height='25' width='100px'><td> Name: </td><td>" + data[i].name + "</td></tr>"
and then clean this out:
$('#detailsfull').find('.specific-data').remove();
.empty()instead of.remove()and add the description of the table as variable. I decided this is a simpler way Thank you for quick answe - Catalin Sterian 2012-04-05 02:57