Removing a dynamically created li from ul

前端 未结 4 1100
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 05:31

I\'m using jquery to add and remove bullets on the fly after the DOM is loaded.

Here\'s the code to add a bullet which works fine:

// add bullet
$(\'         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-07 05:58

    You could do it using the index of the clicked

  • $('li').on('click', function() {
        $(this).parent().children('li:eq(' + $(this).index() + ')').remove();
    });
    

    Edit: this works as well:

    $('li').on('click', function() {
        $(this).remove();
    });
    

    See fiddle.

提交回复
热议问题