I am currently working on this project. My goal is to display a default image if there is no image in the post. The JQuery code I have implemented is:
$(function () {
$(".post").each(function () {
var posthead = $(this).find("h2.post-title").text(),
postlink = $(this).find("h2.posttitle a").attr("href");
if($(this).find("img:first")>=1){
var imageSrc=$(this).find("img:first").attr('src');
}
else{
var imageSrc="http://3.bp.blogspot.com/-P5H7BaGibPg/UjVD-0SIs9I/AAAAAAAADFk/l65svtw9IHg/s320/70-photography-2.jpg";
}
$(this).replaceWith("<div class='post'><img class='thumb' src='" + imageSrc + "'/><div class='posthead'><h2 class='hometitle'><a href='" + postlink + "'>" + posthead + "</a></h2></div></div>");
});
});
This code will assign the attribute src of the first image as the variable imageSrc only if there is an image present. If not, it will use a default image specified in the else condition.