How to change two different background colors in JavaScript using onClick() event for two buttons

javascript onclick change background color of div
change background color on button click in javascript
change background color using javascript function
change button color onclick javascript
angular 7 change background color onclick
javascript program to change background color using array
change background color on button click in html
javascript change background color based on value

I have to make two buttons that will change the background color onclick, the first button will change the background color to yellow and the other one will change the background color into light blue. I have done something like this,

<button id="bttn1" type="button" onclick="changeColor()">Click for a yellow color</button>
<button id="bttn2" type="button" onclick="changeColor()">Click for a light blue color</button>
function changeColor() {
  document.getElementById("bttn1").style.backgroundColor = "yellow";
  document.getElementById("bttn2").style.backgroundColor = "light blue";
}

set the color using document.body.style.background

<script type="text/javascript">
function changeColor(color){
    document.body.style.background = color;
}
</script>
<button id="bttn1" type="button" onclick="changeColor('yellow')">Click for a yellow color</button>
<button id="bttn2" type="button" onclick="changeColor('lightblue')">Click for a light blue color</button>

How to Change Button Color OnClick in Javascript, Programming with Mosh 2,999,275 views � 48:17 � How to Change Background Color after Duration: 4:21 Posted: Nov 11, 2019 Use a JavaScript Function to Change Background Color with Input Textbox or Color Picker - Duration: The onClick Event - Duration: Change Body Background Color Using Color Box

For changing the button background

    <script>
                function changeColorYellow() 
                {
                  document.getElementById("bttn1").style.backgroundColor = "yellow";
                }
                function changeColorLightBlue() 
                {
                  document.getElementById("bttn2").style.backgroundColor = "LightBlue";
                }
                </script>

For changing background-color

    function changeColorYellow() {
        document.querySelector('body').style.backgroundColor = "yellow";
    }
    function changeColorLightBlue() {
        document.querySelector('body').style.backgroundColor = "LightBlue";
    }

Add CSS with it

body {
    height:100vh;
    width:100wh;
}

And change the HTML respectively...

How to change the background color after clicking the button in , Use HTML DOM Style backgroundColor Property to change the Example: This example changes the background color with the help of JavaScript. Approach 2: This approach uses jQuery to change the background color after The on() method is used as event handlers for the selected elements and� // Get the button, and when the user clicks on it, execute myFunction document.getElementById("myBtn").onclick = function() {myFunction()}; /* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */

If you are just trying to change the color of the webpage then you could do something like

<button id="bttn1" type="button" onclick="changeColor("yellow")">Click for a yellow color</button>
<button id="bttn2" type="button" onclick="changeColor("lightblue")">Click for a light blue color</button>
function changeColor(color) {
  document.body.style.backgroundColor = color;
}

How to change the background color of a web page using JavaScript, HTML Tags/Elements HTML Global Attributes HTML Event Attributes HTML Color You can easily change the background color of a webpage i.e. the <body> element or any other element dynamically by using its style property in JavaScript . <button type="button" onclick="changeBodyBg('yellow');">Yellow</button> How to create buttons in Javascript that change the color of an HTML element The onClick Event - Duration: How to Change Background Color after Clicking the Button in Javascript

HTML ondblclick Event Attribute, Well organized and easy to understand Web building tutorials with lots of Execute a JavaScript when a button is double-clicked: The ondblclick attribute fires on a mouse double-click on the element. Browser Support. Event Attribute <p id="demo" ondblclick="myFunction()">Double-click me to change my text color . Javascript Tutorial | Event Handlers in Javascript - Duration: Change Body Background Color Using Color Box How to Change Button Color OnClick in Javascript - Duration:

Using CSS together with JavaScript to show content, By clicking the "Save" button you agree to our terms and conditions. background-color: #4CAF50; color: white; <p class="flip" onclick="myFunction() ">Click to show panel</p> When the user clicks on the p element, a function called myFunction() is executed, which changes the style of the div with id="panel " from� Given an HTML document and the task is to change the background color of the document using JavaScript and jQuery. Approach 1: This approach uses JavaScript to change the background color after clicking the button. Use HTML DOM Style backgroundColor Property to change the background color after clicking the button. This property is used to set

Registering Events in JavaScript, function ChangeColor() { You can also use this type of event registration with multiple HTML elements. The above code defines two buttons named " myButton" and "myOtherButton" and assigns the same event handler to the " onclick"button. We've already created our function to change an element's background color,� Change background color with a loop onclick. process of learning JavaScript. I was trying to get this to loop through each color in the array, but when i click

Comments
  • background-color of buttons or webpage?
  • Does this answer your question? How to change button color onclick using javascript only?
  • Its lightblue not light blue
  • This is very low quality question :<
  • im new to this :( im sorry
  • why are you posting same answer already given by some one else.
  • my answer shows how to change the webpage color not the button color, answering the question asked not saying what the other said