jquery append truncate

Go To StackoverFlow.com

1

I have a selectlist box in Jquery I am doing something like:

      $("#Deg").append(degtems);

As I am calling the above code a number of times, it keeps on appending. How do I trunctate and then append.

Thank

2012-04-03 19:54
by Nate Pet


2

Call .empty() first:

$("#Deg").empty().append(degtems);

..or you could simply use .html() as @KevinB points out below:

$("#Deg").html(degtems);
2012-04-03 19:55
by Colin Brock
Or, you can use .html() which calls .empty() and .append() for the same effect - Kevin B 2012-04-03 19:56
@KevinB: Very true. Thanks - Colin Brock 2012-04-03 19:56


1

Try using .html:

$("#Deg").html(degtems);

It's essentially just doing this:

$("#Deg").empty().append(degtems);
2012-04-03 19:56
by Jasper


0

Use the .empty method on the select element first to remove all children:

$("#Deg").empty()

....
$("#Deg").append(degtems);
2012-04-03 19:56
by Alex Vidal