How to set the decoration of a text with JavaScript?



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>
Updated on: 2020-06-23T11:27:38+05:30

948 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements