$(function(){ // Loop through all the sets of before and after pics $(".beforeafter").each(function(){ // Set the container's size to the size of the image $(this).width($(this).find("img[rel=before]").attr("width")).height($(this).find("img[rel=before]").attr("height")); // Convert the images into background images on layered divs $(this).append("
").find(".after").css({"background": "url(" + $(this).find("img[rel=after]").attr("src") + ")", "width": $(this).find("img[rel=after]").attr("width") + "px", "height": $(this).find("img[rel=after]").attr("height") + "px"}); $(this).append("").find(".before").css({"background": "url(" + $(this).find("img[rel=before]").attr("src") + ")", "width": $(this).find("img[rel=before]").attr("width") - 40 + "px", "height": $(this).find("img[rel=before]").attr("height") + "px"}); // Add a helpful message $(this).append("