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

How to set the color of the text-decoration with JavaScript?


To set the color of the text-decoration, use the textDecorationColor property in JavaScript.

Example

You can try to run the following code to change the color of the text-decoration −

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