How do I make a HTML Button that changes a Web Page background using CSS?
I'm guessing you'd have to implement Java Script
Haven't watched the whole thing but here's a tutorial: https://www.youtube.com/watch?v=jznWWxPZkvQ
This is a loaded question that you would not be able to do with just CSS. You would need JavaScript as well. Lets say this is our HTML: ```html <html> <head></head> <body> <button>Click me</button> </body> </html> ``` In order to tell the button what to do, we would need to give it the `onclick` attribute. In that we would have JavaScript that would tell the browser what to do when the button is clicked. In this case we would use the method `document.getElementsByTagName` in order to get an array of elements with that tagName. Since we are just getting the body, it will always be the first element so we can simplify it to `document.getElementsByTagName("body")[0]` to select the body of the document. The element has a method of `style` which allows us to read and set the style of the element. In this case since you specified background, we will use `style.background`. This means our JavaScript so far is now ```js document.getElementsByTagName("body")[0].style.background ``` Now you just need to set the value of this using a color, so let's say by default it's white, you can change it to black with: ```js document.getElementsByTagName("body")[0].style.background = "black"; ``` You can read more about these API's here: https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByTagName https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
Also gucchi has had a few questions in the past about coding so some of his answers to his questions by smokey and Jay may be able to help you out. I will link one of his closed questions for you to go and be able to look at- https://questioncove.com/study#/updates/626b1997c3268b9ac1a1c80
Join our real-time social learning platform and learn together with your friends!