how can i remove appendet text from a div?

Go To StackoverFlow.com

0

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]

&lt;table id="shorttableinfo"&gt; // i need a small table here

&lt;tr&gt;&lt;td&gt;Name:&lt;/td&gt;&lt;td&gt; [other minimal data] &lt;/td&gt;&lt;/tr&gt;

&lt;/table&gt;

[other html code]

&lt;table id="detailsfull"&gt; // i need a small table here

&lt;tr&gt;&lt;td&gt;Name:&lt;/td&gt;&lt;td&gt; [other minimal data] &lt;/td&gt;&lt;/tr&gt;

&lt;/table&gt;

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.

2012-04-05 01:51
by Catalin Sterian


0

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

2012-04-05 01:58
by Andreas Wong
i have decided to use .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


0

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();
2012-04-05 01:59
by binarious
Ads