Change the color of the line, in an underlined text:
document.getElementById("myP").style.textDecorationColor = "red";
Click the button to change the color of the underline.
<!DOCTYPE html> <html> <head> <style> p#myP {/*w w w .ja va2 s .co m*/ text-decoration: underline; } </style> </head> <body> <p id="myP"> Hello world! </p> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myP").style.textDecorationColor = "red"; } </script> </body> </html>
The textDecorationColor property sets the color of the text-decoration: underline, overline, linethrough.
Property Values
Value | Description |
---|---|
color | Sets the color of the text-decoration |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The textDecorationColor property returns a String representing the text-decoration-color property of an element.