12. Append to Body


#1

I have gone through almost 5-7 posts regarding same class but it seemed I have different error as it is not a typo/syntax error I could identify myself, however I used this code on Visual Studio Code editor and it worked fine
Please review my code trying to append() new div when button is clicked while maintaining variable scope.

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

Error message says ( ops, try again. Make sure to use .append() to add your .item to your .list! )

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


#2

here:

$('div.list')

even though this is correct, the exercise does not seem to approve it. Try $('.list')


#3

Negative, I used both of them and same error message appeared.


#4

after submitting, did the preview window go to full screen? Did you add elements to your list?


#5

Yes, the code worked fine and I could see new

lines when I make an input and press 'add' button.

I copied this code and the class is succeeded but I didn't get it :

$(document).ready(function(){
    $("#button").click(function({
        var toAdd = $("input[name=checkListItem]");
        $(".div").appendClass("item"); 
    });
});

#6

back to this code:

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

all you needed to do was change $('div.list') into $('.list'), not sure why you changed what you did

if you submit, the preview page should go full page, add some items and you should be good


#7

It worked now after removing 'div' from $('selector') and after using the other code I indicated above! Haha, crazy couple lines of code.

Thank you Stetim94 for helping solving this riddle :smiley:


#8