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.


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

Live Demo

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