+1 vote
by (98.9k points)
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

1 Answer

0 votes
by (98.9k points)
Best answer
<!DOCTYPE html>

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

function red() {
document.body.style.backgroundColor ="red";

function green() {
document.body.style.backgroundColor ="Green";


Related questions

+1 vote
1 answer 53 views
+1 vote
1 answer 180 views

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


506 users