0

I can't get the original code that is supposed to make the background green when you press the button and I can't figure out how to add the gradient as the color. Please help!

here is my code:

<html>
  <body>
    <button onclick="myFunction()">Green <em>Gradient</em></button>

    <script>
      function myFunction()
      */I want this to be a gradient, but I cant figure out how/*
{   
document.body.style.backgroundColor= "green";
}

    </script>

  </body>
</html>
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 2
    Does this answer your question? [How do you make a gradient background in css?](https://stackoverflow.com/questions/9428893/how-do-you-make-a-gradient-background-in-css) – John Montgomery Jun 17 '20 at 00:30

2 Answers2

1

Just an example you might be able to edit to your liking.

/*I want this to be a gradient, but I cant figure out how*/
function myFunction(){ 

  document.body.style.background= "linear-gradient(90deg, rgba(212,211,222,1) 0%, rgba(186,215,209,1) 26%, rgba(0,255,44,1) 100%)";
}
<html>
  <body>
    <button onclick="myFunction()">Green <em>Gradient</em></button>
  </body>
</html>
Karl L
  • 1,645
  • 1
  • 7
  • 11
  • yes, to simplify this. it would look like this : background: linear-gradient(to right,#FFFFFF, #278c2b); – Karl L Jun 17 '20 at 01:08
0

/*I want this to be a gradient, but I cant figure out how*/
function myFunction(){ 

  document.body.style.background= "linear-gradient(90deg, rgba(212,211,222,1) 0%, rgba(186,215,209,1) 26%, rgba(0,255,44,1) 100%)";
}
<html>
  <body>
    <button onclick="myFunction()">Green <em>Gradient</em></button>
  </body>
</html>