+1 vote
59 views
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>
<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>

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

108 comments

506 users

...