arboles
arboles

Reputation: 1331

Using jquery toggle, after appending an element, how do i remove that element?

How do i remove var icon element once i have appended it? the current method is not working.

i tried the way explained here but it didnt work.

JQUERY

$('#edit').toggle(function(){
    $('#edit').text('Close');
    var icon='<i class="icon-remove"></i>';
    $('.para').append(icon);
}, function(){
    $('#edit').text('Edit');
    var $icon = $(icon).not('i');
    $('.para').append($icon);
});

this doesnt work either

    $('#edit').toggle(function(){
    $('#edit').text('Close');
    var icon='<i class="icon-remove"></i>';
    $('.para').append(icon);
}, function(){
    $('#edit').text('Edit');
    var icon='.remove';
    $('.para').remove(icon);
});

HTML/PHP

foreach ($users_tags as $key => $list) {
echo '<span>'.$list['tag_name'].'<span class="para"></span> </span>. ';
}

Upvotes: 0

Views: 2027

Answers (1)

jbduzan
jbduzan

Reputation: 1126

you can do it like that

('#edit').toggle(function(){
    $('#edit').text('Close');
    var icon='<i class="icon-remove"></i>';
    $('.para').append(icon);
}, function(){
    $('#edit').text('Edit');
    var $icon = $('.icon-remove');
    $icon.remove();
});

Upvotes: 2

Related Questions