Why will it not work?


#1

I don't get it as well.

If i put the code below after i have taken inputs from the user, why will it not work? In the below, i have taken inputs from the user in the form and ONLY THEN am i calling the $(this).remove(). Still not clear why this wouldn't work

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

13/14: Why must use `on` handler
#2

Hi @stickysplatt,

You need to separate the different sections of code, rather than nesting them all inside each other :slight_smile:

Your code structure should look like this: ←

$(document).ready(function() {
  $('#button').click(function() {
    // ...
  });

  $('.item').click(function() { // ← this part comes *after* the 
                                 // other code segment above it
    // ...
  });
});

If you're still having trouble, please post a link to the exercise you're on, your updated code, and the error message you're getting :slight_smile: