Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Entities with jQuery

I would like to use replace the value of a submit button with Loading….

The problem is that when I click the button I still see … instead of three dots.

Here's my code:

$("#myid").val("Loading…");

Should I enter the ellipsis directly from the keyboard in the code above? Is it safe with UTF-8?

like image 661
collimarco Avatar asked Nov 29 '22 19:11

collimarco


2 Answers

val() or value sets a plain text value. … is HTML, not text; you could use it in innerHTML or .html(), but not in a form field value.

If you want to include U+2026 HORIZONTAL ELLIPSIS in a JavaScript string where the encoding is not guaranteed, you could escape it to:

'Loading\u2026'

Should I enter the ellipsis directly from keybord in the code above? Is it safe with UTF-8?

Yes.

However, the ellipsis has a compatibility decomposition into three period characters; it is really only there for backwards compatibility with older character sets. These days the idea is just to use three periods, and let the font deal with coming up with combined glyphs if necessary. In any case, there is little to no visual difference between three periods and an ellipsis in most (proportional) fonts.

like image 199
bobince Avatar answered Dec 09 '22 15:12

bobince


Just as note, these are the useful spanish characters

\u00E1  á
\u00E9  é
\u00ED  í
\u00F1  ñ
\u00F3  ó
\u00FA  ú

\u00C1  Á
\u00C9  É
\u00CD  Í
\u00D1  Ñ
\u00D3  Ó
\u00DA  Ú

I've created a useful tool to convert whatever you want to the corresponding \uVALUE in JS :) http://jsfiddle.net/tomasdev/VjAkJ/

like image 40
Tom Roggero Avatar answered Dec 09 '22 14:12

Tom Roggero