Answers for "html button onclick change color"

CSS
14

css onclick change color

<style>
.dabutton:focus {
    background-color:yellow;
}
</style>
<button class="dabutton"></button> // <-- usage
Posted by: Guest on July-03-2020
0

change the button color on click

button:active{
  background-color:green;
}
Posted by: Guest on August-16-2021
12

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 "html button onclick change color"

Browse Popular Code Answers by Language