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

How to set the color of the top border with JavaScript?


To set the color of the top border in JavaScript, use the borderTopColor property. Set the color of the top border using this property.

Example

You can try to run the following code to learn how to set the color of the top border with JavaScript −

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            border: thick solid gray;
         }
      </style>
   </head>

   <body>
      <div id = "box">Demo Text</div>
      <br>
      <br>

      <button type = "button" onclick = "display()">Change top border color</button>

      <script>
         function display() {
            document.getElementById("box").style.borderTopColor = "green";
         }
      </script>

   </body>
</html>