Ad
Is There A Button Function To Completely Remove Background?
I'm having trouble with a button function. I have an HTML document with a background set for all pages (in order to keep a common theme). I created a button on one of my pages with the intent of removing the background on that one specific page. I used a script function to change the background color to white. When I press the button, the background changes to white, except for the parts that have text (see images linked below). How can I get the button to essentially remove the entire background?
Here is the code I have so far:
<body>
<style>
body {
background-image: url(IMG_7305.JPG);
background-size: cover;
background-attachment: fixed;
</style>
<button id="button" type="button" onclick="myFunction()"> Press here to remove the background image </button>
<script>
function myFunction() {
document.getElementById("about").style.backgroundColor = "white"
}
</script>
<p>
I want the background to be cleared... even here!!
</p>
Ad
Answer
You need to target the body where the image is, not just the "about" element.
function myFunction() {
document.querySelector("body").style.backgroundImage = "none";
}
body {
background-image: url('https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/beach-quotes-1559667853.jpg');
background-size: cover;
background-attachment: fixed;
}
<button id="button" type="button" onclick="myFunction()"> Press here to remove the background image </button>
<p>
I want the background to be cleared... even here!!
</p>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad