JQuery not removing added element
        Posted  
        
            by Scott
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Scott
        
        
        
        Published on 2010-03-22T08:37:44Z
        Indexed on 
            2010/03/22
            8:51 UTC
        
        
        Read the original article
        Hit count: 224
        
jQuery
What I want to do is add and remove list items. I have got it to add new items to the list and I can remove existing ones but not the ones that have been added. It seem like it would work but it doesn't. Any help would be appreciated! Here the code:
JQuery:
<script  type="text/javascript">
$(function(){
    $('a#add').click(function(){
        $('<li><a href="#" id="remove">--</a>List item</li>').appendTo('ul#list');
    });
    $('a#remove').click(function(){ 
        $(this).parent().remove();
    });
});
</script>
HTML:
<a href="#" id="add">Add List Item</a>
<ul id="list">
<li><a href="#" id="remove">--</a> List item</li>
<li><a href="#" id="remove">--</a> List item</li>
<li><a href="#" id="remove">--</a> List item</li>
<li><a href="#" id="remove">--</a> List item</li>
</ul>
© Stack Overflow or respective owner