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

HTMLJavascriptProgramming Scripts

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 −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Click to Set background Color</button>
      <script>
         function display() {
            document.body.style.backgroundColor = "blue";
         }
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 18:53:33
Advertisements