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

How to set the style of the line in a text decoration with JavaScript?


To set the style of the line in JavaScript, use the textDecorationStyle property. You can set underline, double, or overline, etc for the line style.

Example

You can try to run the following code to return the style of the line in a text-decoration with JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <div id = "myText" style = "text-decoration: underline;">
         This is demo text.
      </div>
      <br>
      <button onclick = "display()"> Set Text Decoration </button>
      <script>
         function display() {
            document.getElementById("myText").style.textDecorationColor = "red";
            document.getElementById("myText").style.textDecorationStyle = "double";
         }
      </script>
   </body>
</html>