function underline() {
var text = document.getElementById("note_header").style.textDecoration;
if (text == 'normal') {
document.getElementById("note_header").style.textDecoration = 'Underline';
} else {
document.getElementById("note_header").style.textDecoration = 'normal';
}
}<input id = "btn" type = "button" value = "Underline" name = "btn" onclick = "underline()">Голосующий против, не могли бы вы добавить комментарий для голосования против.
используйте if (text == '') вместо if (text == 'normal')
<input id = "btn" type = "button" value = "Underline" name = "btn" onclick = "underline()">
Я не вижу ни одного элемента с note_header в качестве идентификатора, не могли бы вы также включить его?
note_header просто представляет текстовую область, в которой я набираю текст, который нужно подчеркнуть.
Это работает так: jsfiddle.net/khrismuc/2hpxj58g (вам нужно будет использовать getComputedStyle(), а по умолчанию none, а не normal)
@ChrisG спасибо за ваш ответ.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Попробуй это
function underline(){
var text = document.getElementById("note_header").style.textDecoration;
if (text == 'none'){
document.getElementById("note_header").style.textDecoration = 'Underline';
} else{
document.getElementById("note_header").style.textDecoration = 'none';
}
}<a href = "#" id = "note_header" style = "text-decoration:none;">This is anchor</a>
<input id = "btn" type = "button" value = "Underline" name = "btn" onclick = "underline()">normal не является допустимым значением для text-decoration. Вместо этого используйте none.
function underline(){
var text = document.getElementById("note_header").style.textDecoration;
if (text !== 'underline'){
document.getElementById("note_header").style.textDecoration = 'underline';
} else{
document.getElementById("note_header").style.textDecoration = 'none';
}
}<textarea id = "note_header" rows = "3" cols = "15">
That's my note
</textarea><br/>
<input id = "btn" type = "button" value = "Underline" name = "btn" onclick = "underline()">
покажите свой html, а также укажите, как вы вызываете функцию