Computer >> Computer tutorials >  >> Programming >> Javascript

How to return the background color of an element with JavaScript DOM?


To return the background color in JavaScript, use the backgroundColor property. It allows you to return the background color.

Example

You can try to run the following code to learn how to return the background color of an element with JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Click to Set background Color</button>
      <script>
         function display() {
            document.body.style.backgroundColor = "blue";
         }
      </script>
   </body>
</html>