I am fetching result from database and i want too append it to dynamically created div.
for (j = 0; j <= 2; j++)
{
selected = $(".content" + (j + 1));
ajax1(arr[j]);
}
function ajax1(pref) {
$.ajax({
async: false,
url: "../handlers/guestpreference.ashx",
data: { "pref": pref },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: guestsuccess,
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
alert(thrownError);
}
});
}
function guestsuccess(resultset)
{
$.each(resultset, function (i, data) {
$(selected).append('<div class="blogpost" >');
$(".blogpost").append("<div class='blogposth'>");
$(".blogpost").append("<div class='blogpostf'>");
$(".blogposth").append('<font style="font-size:30px; color:blue;padding-left:10px;margin-top:10px;">' + data.Name + '</font>');
$(".blogpostf").append('<font style="font-size:30px; text-align:centre;">' + data.Title + '</font><br>');
$(".blogpostf").append('<font style="text-align:left;float:left;">' + data.Post + '</font><br>');
$(".blogpostf").append('<hr>');
var likes = data.Likes;
if (likes > 0)
$(".blogpostf").append('<font style="font-size:10px;text-align:left;float:left;">' + likes + ' people like it.</font><br>');
else
$(".blogpostf").append('<font style="font-size:10px;text-align:left;float:left;">Nobody like it.</font><br>');
$(selected).append("<br>");
});
}
Here selected holds the class where i have to append .blogpost.
this code is working fine if i have only 1 row of result but in case of multiple result the results are being appended to previously created div.
Since i have CSS for .blogpost .blogposth .blogpostf how can i modify my code so that i can append value uniquely.