lwalden
lwalden

Reputation: 803

can't get unicode character to display properly - Javascript and HTML

I'd like to put a unicode up arrow in an html input button that is being generated in Javascript.

These are the codes for the up arrow from unicode-table.com:
Unicode number: U+2191
HTML-code: & #8593; (space between the & and # so you can see the code and not the arrow)

I do have
<charset="utf-8" /> in my head tag in the html file.

I've tried every variation of those two codes I can think of within the <> below and all I get in the browser is the text of the codes I've tried.

Here's the line of code:

upButton.setAttribute("value", "<up arrow code here>");

Upvotes: 1

Views: 3379

Answers (3)

Mathias Bynens
Mathias Bynens

Reputation: 149484

To escape any symbol in JavaScript, use this tool: http://mothereff.in/js-escapes#1%E2%86%91 For your example, '↑' becomes '\u2191'.

To escape any symbol in HTML, use this tool: http://mothereff.in/html-entities#%E2%86%91 For your example, becomes &#x2191; or &uarr;.

Upvotes: 2

ThorSummoner
ThorSummoner

Reputation: 18089

try this string instead of an html escape character (this is a JavaScript string after all, not an html text node) \u2191'

Upvotes: 5

3abqari
3abqari

Reputation: 208

Try using this in your html: &uparrow;

Upvotes: 0

Related Questions