Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Last active August 29, 2015 14:16
Show Gist options
  • Save codenamejason/e9293841054032957ae3 to your computer and use it in GitHub Desktop.
Save codenamejason/e9293841054032957ae3 to your computer and use it in GitHub Desktop.
Change background image with button
#imgDiv {
width: 400px;
height: 400px;
background-image: url('http://placehold.it/400.png&text=New_Image/464545/e743c3');
}
<div>
<button onClick="myFunction()">Change Background</button>
</div>
function myFunction() {
document.getElementById("imgDiv").style.backgroundImage = "url(http://placehold.it/400.png&text=New_Image/464545/e743c3)";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment