Removing a dynamically created li from ul

前端 未结 4 1067
佛祖请我去吃肉
佛祖请我去吃肉 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:44

    Don't you mean

    $(this).parent().remove();
    

    Also, you might want to consider

    $(this).closest('li').remove();
    

    That will go up the DOMtree until it finds a li, if you ever wrap your anchor in another element, the last example wont brake :)

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题