burgoyne burgoyne - 26 days ago 7
HTML Question

Can't remove a list item?

I am trying to remove a list item.

I add an item in like so:

$('#btnAdd').click(function(){
var text = $('#item').val();
if(text.length){
$('<li />',{html: text}).appendTo('ul.justList')
}
});


then remove it like so:

$('#btnRemove').click(function(){
$("#justList li:last-child").remove();
});


Why does the last list item not remove? Any suggestions? Thanks so much!

Answer

Based on your add statement I would guess that you need a remove statement like:

$('#btnRemove').click(function(){
    $("ul.justList li:last-child").remove();
});

If your add statement is working then this should be accessing the same ul