Use the textDecoration property in JavaScript to decorate the text. You can underline a text using this property.
Example
You can try to run the following code to set the decoration of a text with JavaScript −
<!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"; } </script> </body> </html>