gnganapath
gnganapath

Reputation: 947

How to remove append value in jquery

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

Answers (3)

Shahadat Hossain
Shahadat Hossain

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

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
}


Or

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
}


If you just have to show count in div nothing else use

$('#dropitemcount').text(count);

Upvotes: 0

uesports135
uesports135

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

Related Questions