Reputation: 1
I have a lists of images with the same class. When I click one of the images, I would like jQuery to grab the source of the image and apply it to the body background. Is that possible?
Upvotes: 0
Views: 34
Reputation: 16733
You are looking for something like this:
$(document).on('click', 'img.myClass', function(){
var src = $(this).attr('src');
$(body).css('background-image', src);
});
Upvotes: 1
Reputation: 13049
$("img.myClass").click(function(image){
$(body).css('background-image', $(image).attr('src'));
});
Upvotes: 0