user1396371
user1396371

Reputation: 1

Set image as background

I want to make a site where there are some images, when I click on an image I want it to be the background image of the site, any suggestion?

Upvotes: 0

Views: 1001

Answers (3)

DFIVE
DFIVE

Reputation: 263

if you know how to use JQuery, this should be easy:

$('#divTagId').click(function()
{
  $("html").css("background-image", "url(/myimage.jpg)");  
});

Upvotes: 0

ericosg
ericosg

Reputation: 4955

This can be done easily as per below:

jQuery:

$(function(){
    $("#imageId").click(function() {
        var myImage = $("img", this).attr("src");
        $("body").css("background", "url('" + myImage + "')");
    });
});

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324610

Something along the lines of:

<img src="myimage.jpg" onClick="document.body.style.backgroundImage = 'url('+this.src+')';;" />

Upvotes: 3

Related Questions