menu search
brightness_auto
more_vert
Write a Javascript to change the background color of the web page to red color if button named “RED” is clicked and to green color if button named “GREEN” is clicked
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer
<!DOCTYPE html>
<html>

<body>
 <button onclick="red()">red</button>
<button onclick="green()">Green</button>

<script>
function red() {
document.body.style.backgroundColor ="red";
}

function green() {
document.body.style.backgroundColor ="Green";
}
</script>
</body>

</html>
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

Related questions

thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

648 users

...