How to set the style of an element's border with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To set the style of an element’s border, use the borderStyle property in JavaScript.

Example

You can try to run the following code set in the style of an element’s border with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         #newDiv {
            height: 150px;
            width: 150px;
            border: 2px solid #000000;
         }
      </style>
   <body>
      <div id="newDiv">
         Demo Content!
      </div>
      <br>
      <button type="button" onclick="display()">Change border style</button>
      <script>
         function display() {
            document.getElementById("newDiv").style.borderStyle = "dashed";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 10:28:57
Advertisements