HTML character code to underline next character

Alex picture Alex · Jan 4, 2012 · Viewed 8.8k times · Source

Like:

abcdef 
 _

What HTML character code I need to insert before b to make b underlined?

I need this inside a html attribute (value of a input field), so html tags like <u> are not acceptable


example:

<input type="submit" value="UnderlineMeifUknowHow" accesskey="n" />

I want the first "n" from UnderlineMeifUknowHow to be underlined

Answer

Paulo Roberto Rosa picture Paulo Roberto Rosa · Jan 22, 2014

You can simply put &#818; after any word and it becomes underlined, its a HTML Code.

<input type=button value=S&#818;end>

It becomes:

S̲end

But you can create a JavaScript function to do it for you, see:

function underlineWord(pos,str){
  str = str.substring(0,pos) + str[pos] + "&#818;" + str.substring(pos+1,str.length);
  return str;
}

This way, if you execute:

underlineWord(0,"string");

You will have:

s̲tring