12. Append to Body


#1

This is my code but I can't pass the lesson!!! Is there anything wrong with it?

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

#2

instruction:
.append() a <div> with class="item" to the .list div

but you've write list class
$('.list').append('<div class="list">' + toAdd + '</div>');

should be class="item"


#3

"$('.list').append('

' + toAdd + '
');"
It is already appending in the
with list class [$('.list').append]. so you do not need to tell again inside the .append object [.append('
]. find an example below-
    $('#messages').append("<p>"+toAdd+"</p>");

This code will add the input item to message div as

, test the code with different tag, i.e. h4 tag or li tag , so you will understand the difference.

Happy Coding :slight_smile:


#4

in your html should be

' + toAdd + '

#5

Is an issue also in enclosing checkListItem in quotes? example: var toAdd = $("input[name='checkListItem']").val();

In the previous exercise we were not expected to use quotes. example: var toAdd = $("input[name=checkListItem]").val();


#8