Reputation: 947
This is my code. It's working for first item append.
When click show count button I show in pop up dialog box. But removal of that append or reload page is required
function showcount()
{
$('#dropitemcount').append(count);
}
Output is : 2
When i click again that show button
output is : 2 2
third time : 2 2 2
How to resolve this item?
It's possible to elemetn.remove().append()
Upvotes: 0
Views: 1895
Reputation: 21
Try this if it is helpful to you.
var count="<span>"+count+"</span>";
function showcount(){
$('#dropitemcount').find('span').remove();
$('#dropitemcount').append(count);
}
Upvotes: 2
Reputation: 57105
Try
var dropitemcount = $('#dropitemcount');//cache selector
function showcount() {
dropitemcount.find('span').remove(); //remove span
dropitemcount.append('<span>' + count + '</span>'); //add new span with new count
}
Change your html add span
tag inside it
var dropitemcount = $('#dropitemcount'); //cache selector
function showcount() {
dropitemcount.find('span').text(count); //set text of count to span
}
$('#dropitemcount').text(count);
Upvotes: 0
Reputation: 1123
I might be misunderstanding your question but it looks like append is doing exactly what you're telling it to do. If your trying to change the content than try this:
$('#dropitemcount').html(count);
Also, make sure you increment your count as well.
Upvotes: 0