1

Would it be possible to change the background of the html page when clicking a page?

0

3 Answers 3

1

yes, all you have to do is apply a css class that changes the background on the click event, if you can provide a code sniplet i can help you achieve this.

Sign up to request clarification or add additional context in comments.

1 Comment

Wait, can you change the background of the body with the click event?
1

Something like this:

<html>
<head>
    <title>Javascript Change Div Background Image</title>

    <style type="text/css">

    #div1 {
    width:100px;
    height:30px;
    background-image:url(images/blue.gif);
    }

    p {
    font-family:Verdana;
    font-weight:bold;
    font-size:11px
    }

    </style>

    <script language="javascript" type="text/javascript">
    function changeDivImage()
    {
        var imgPath = new String();
        imgPath = document.getElementById("div1").style.backgroundImage;

        if(imgPath == "url(images/blue.gif)" || imgPath == "")
        {
            document.getElementById("div1").style.backgroundImage = "url(images/green.gif)";
        }
        else
        {
            document.getElementById("div1").style.backgroundImage = "url(images/blue.gif)";
        }
    }
    </script>

</head>

<body>

    <center>
    <p>
        This Javascript Example will change the background image of<br />
        HTML Div Tag onclick event.
    </p>
    <div id="div1">
    </div>
    <br />
    <input type="button" value="Change Background Image" onclick="changeDivImage()" />
    </center>

</body>
</html>

But if you are using jQuery it would be a lot easier to do ! If you are using jQuery just edit your question

$(function(){
    $("input").click(function(){
        $("body").css("background","url('otherimg.jpg')"); 
    });
});​

Comments

1
    $(function(){
$("input").click(function(){
    $("body").css({background-image:"url('imageName.gif')"}); 
});
});​

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.