I am trying to make a button that would change the background image of the whole document whenever somebody clicks it. I have tried something along the lines of this: and, as you can see, I am a beginner at coding in general so any help is appreciated. My assumption to why it doesn't work is that I am combining javascript with CSS, but I am most likely wrong.
Try this : <script> function change(bg) { document.body.style.backgroundImage = bg; document.body.style.backgroundPosition = "top center"; document.body.style.backgroundRepeat = "no-repeat"; } </script> <input type="button" value="Pattern1" onClick="change('background.png') />"; HTML: