How do I use the jQuery $.each method to output proper HTML?

each, javascript, jquery, json

Solution

   var obj = JSON.parse(data); 

    $.each(obj.items, function (i, item) { 
        $("<p>" + item.title + "</p>").appendTo("#twitter > span"); 
        if (i == 5) return false; 
    });

Problem

HTML: ``` <div id="twitter" style="float:left;"> <span></span> </div> ``` jQuery: ``` var obj = JSON.parse(data); $.each(obj.items, function(i, item) { $("span", this).html("('<p>" + item.title + "</p>')").appendTo("#twitter"); if (i == 5) return false; }); ``` I'm obviously doing something wrong, and can't seem to figure this out. I know the $.each method works, as I'm able to put alert(item.title) and get the expected result. Basically all I want to do is, loop through the item and output: ``` <p> title </p> <p> title 2 </p> ``` I just can't seem to figure this out

Original source