"14. You did it!" - did I?


#1

Hey guys,

So I'm really confused about the 'Mastering Manipulations' section of 'Modifying HTML Elements'. I seem to have been able to get through all the lessons, but my checklist is not actually doing anything. Clicking the button does nothing at all.

Here's a link to the lesson:

"14. You did it!"

Here's my code:

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

I imagine it's something to do with this bit:

 var toAdd = $('input[name=checkListItem]').val();
     });
     $('.list').append('\
<div class="item">' + toAdd + '</div>');

as I didn't really know what I was doing at that point.

Thanks in advance,

Daniel


#2

So I managed to solve my own problem. Went through the section again paying a little more attention this time. Code now reads:

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

and works fine.

I am a little disappointed however that I managed to complete the course both whilst my code wasn't adding anything and later when it was adding but not removing list items. So basically my code was completely wrong in two cases but the course was telling me it was fine both times. :unamused: