0

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>. ';
}
Community
  • 1
  • 1
arboles
  • 1,321
  • 4
  • 20
  • 39

1 Answers1

2

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();
});
jbduzan
  • 1,106
  • 1
  • 14
  • 30