Does anyone see what I'm doing wrong. It won't remove items but it lets me move on to next lesson


#1

$(document).ready(function(){
$('#button').click(function(){
var toAdd = $('input[name=checkListItem]').val();
$('.list').append('<div class="item">' + toAdd + '</div>');
});
$(document).on('click', '.item', function(){
$('<div class="item">' + toAdd + '</div>').remove();
});
});

It's letting me move on to the next lesson but after I add an item I can't remove it and I'm getting a
Uncaught ReferenceError: toAdd is not defined message.


#2

Hi Jason,

↑ You should replace that (the second one) with the jQuery object, $(this). That HTML is only for when you're adding a list item :slightly_smiling:


#3

Thanks zystvan, That makes sense. I don't know why that didn't cross my mind.