Removing a dynamically created li from ul

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

    I used a combination of the answers provided.

    I removed the onclick in the li, and instead referenced the class being clicked and combined that with 'this' as per below.

    $('#linkedEventList').on('click', '.itemDelete', function(){
    $(this).parent().remove();
    });
    

    Here's the jsfiddle that works in both FireFox and Chrome: http://jsfiddle.net/jjgelinas77/CsAJn/27/

提交回复
热议问题