Append to body RESULT


#1

hi,

my code passed but the result is little confusing

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

result

why does the result display in red when i didnt have a CSS for the DIV 'item',There is div for list but not for item so why is the text color red?


#2

Hey, item is under list thus it uses its style..


#3

so append works like this

<div class = 'list'> <div class ='item'> </div></div> ??


#4

sorry the code didnt paste ...i kind of understood it as i played with the code little bit....so the appended div is

between the existing DIV and not a new row


#5

When you append something it adds it as the last child of the element.
Read more here


#6

Thanks! it was very helpful...understood append little better now!!