douhun7609
2012-05-14 07:48 阅读 37

使用jquery切换,在追加元素后,如何删除该元素?

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>. ';
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douxing9228 douxing9228 2012-05-14 07:51

    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();
    });
    
    点赞 评论 复制链接分享

相关推荐