Answers for "change background color using javascript onclick"

9

javascript change background color

document.body.style.backgroundColor = "yellow";
Posted by: Guest on July-08-2020
2

how to change background color using js

var warning = document.getElementById("warning");
  warning.style.background-color = "red";
Posted by: Guest on August-30-2020
1

change background color on button click in javascript

<style>
  .bg1 {
  	background-color: red;
  }
</style>

<button id="btnChangebgColor" />

<script>
  	$(document).ready(function(){
      $("#btnChangebgColor").click(function() {
        $(this).addClass(".bg1");
      }); 
	}
</script>
Posted by: Guest on March-17-2021
0

javascript-change color onclick()

const btn = document.querySelector('button');

function random(number) {
  return Math.floor(Math.random() * (number+1));
}

btn.onclick = function() {
  const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
  document.body.style.backgroundColor = rndCol;
}
Posted by: Guest on June-29-2021

Code answers related to "change background color using javascript onclick"

Code answers related to "Javascript"

Browse Popular Code Answers by Language