call:
$('#tidm').html(''); // .empty() is slightly faster
before your each loop, this will clear the old HTML
Edit: My initial answer was just to clear the html but some of the comments point out valid performance issues in the code from the original question. So, while the performance of the original code wasn't subject of the question I'm going to update my answer with what I believe would be more performant.
I havent tested this but the intention should be clear.
$(document).ready(function() { var $tidm = $('#tidm'); var html; setInterval(function() { $.get('Stocks', function(data) { html = ''; $tidm.empty(); // using empty instead of .html('') as suggested $(data).find('stock').each(function() { var $stock = $(this); var tidm = $stock.find("tidm").text(); var name = $stock.find("name").text(); var price = $stock.find("price").text(); var change = $stock.find("change").text(); html += '<p>tidm = ' + tidm + '</p>'; html += '<p>name =' + name + '</p>'; html += '<p>price = ' + price + '</p>'; html += '<p>change = ' + change + '</p>'; }); $tidm.html(html); }); }, 1000); // 1000 milliseconds = 1 second. });
If there are any other improvements that could be made or mistakes I've made let me know in the comments.