Fowlzy
Fowlzy

Reputation: 17

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>

Upvotes: 0

Views: 4082

Answers (2)

Dhruv Ramani
Dhruv Ramani

Reputation: 2643

Here's a solution:

<button type="button" onclick="myFunction2()">underline</button>

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

Upvotes: 0

George
George

Reputation: 36784

Change the textDecoration property from the style object which, in turn, will modify the text-decoration CSS style:

function underline_text(){
    document.getElementById("myP").style.textDecoration = "underline";
}

JSFiddle

Upvotes: 3

Related Questions