How can I format the text in a JavaScript alert box? I need a word in the text to be underlined.
Underline a string using unicode character '\u0332'
, called a COMBINING LOW LINE
function underline(s) {
var arr = s.split('');
s = arr.join('\u0332');
if (s) s = s + '\u0332';
return s;
}
var str = underline('hello world'); // "h̲e̲l̲l̲o̲ ̲w̲o̲r̲l̲d̲"
alert(str);
This method is not guaranteed to produce a smooth underline.
Example of confirm()
on Firefox 59: