Html OnClick change background image

javascript change background image on click
javascript remove background-image
change background image on button click in javascript
how to change background image automatically using javascript
how to set background image dynamically in html
change background-image on click css
css background image
how to set background image in canvas using javascript

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

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.

How to change css background-image on click?, How to change css background-image on click? javascript css html. I'd like to change the css "background-image:" when someone clicks a button� The backgroundImage property sets or returns the background image of an element. Tip: In addition to the background-image you should also specify a background-color. The background-color will be used if the image is unavailable.

Something like this:

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

    <style type="text/css">

    #div1 {

    p {


    <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)";
            document.getElementById("div1").style.backgroundImage = "url(images/blue.gif)";



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


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


onClick change background picture of div - JavaScript, I've tried placing the array inside and out of the page ready, same with the onclick .. thinking maybe it could just be an issue with scope. change the image of body using html button by applying javascript function.. onclick method is used on button.


Change background image using Javascript with Html Button , change the image of body using html button by applying javascript function.. onclick method Duration: 5:31 Posted: 28 Jul 2017 as you can see I tried passing a function on the onclick attribute and I have already defined these function on the bottom already and still the background image wont change. I have checked the directory where the images are they are correct. and I havent defined any background image on my css so.

HTML DOM Style backgroundImage Property, Style backgroundImage Property. Set a background image for a document: body. backgroundImage = "url('img_tree.png')"; Set a background image of a specific <div> element: backgroundImage = "url('img_tree.png')"; Return the background image of a specific <div> element: alert(document. Return the background image of a The most you could do is to trigger a background image change when hovering the LI. If you want something to happen upon clicking an LI and then staying that way, then you'll need to use some JS. I would name the images starting with bw_ and clr_ and just use JS to swap between them.

Change background image on click - Javascript, I'm trying to get my background images to change when a link or button is $(' html,body').css('background', '#fff url("' + i + '") no-repeat center� If you want the background image to cover the entire element, you can set the background-size property to cover. Also, to make sure the entire element is always covered, set the background-attachment property to fixed: This way, the background image will cover the entire element, with no stretching (the image will keep its original proportions):

How to write a function in JavaScript that will change the , innerHTML = "click to change background image"; var img_holder Does the function (in JavaScript) follow the order in which it's written like the HTML? Firstly, it enables you to add the onClick JavaScript event which will be used to trigger (or call) the function to handle the changing of images. Secondly, it’ll enable you to apply a style to the text using CSS.

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