13. Remove What's Been Clicked - Using a 2nd $(document)


#1


https://www.codecademy.com/en/courses/web-beginner-en-v6phg/2/4?curriculum_id=50a3fad8c7a770b5fd0007a1


Hey I'm just revisiting this exercise and I'm curious about why I have an $(document) inside of another.The code below passes the exercise, but is there better syntax for using .on()? Why is the document the selector twice in a row? Is this exercise meant to be done a different way?

$(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();
    });
});


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.