Search code examples
javascripthtmlcssunderline

HTML underline button


Hi there I am working on making a word processor, and need to make a button to underline the text in the text area. I have made one button that makes the text italic but unsure on the underline button. Any help would be appreciated

<textarea rows="10" cols="100" id="myP" >
      Type text here...
</textarea>
      <br>
      <br>
<button type="button" onclick="myFunction()">Set font Italic</button>

<script>
function myFunction() {
document.getElementById("myP").style.fontStyle = "italic";
}
</script>

Solution

  • Here's a solution:

    <button type="button" onclick="myFunction2()">underline</button>
    
    <script>
    function myFunction2() {
    document.getElementById("myP").style.textDecoration = "underline";
    }
    </script>