1

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>");
lwalden
  • 813
  • 7
  • 11
  • If stuff is being treated as HTML, etc, use the code formatting, that's what it's there for. – alex Apr 03 '14 at 04:28
  • not sure what you mean by that @Alex. It seems if I create the button in the html file it works fine, but create th button in Javascript and it will not. For my purposes I need to create it in Javascript, however. – lwalden Apr 03 '14 at 04:35
  • possible duplicate of [Insert Unicode character into JavaScript](http://stackoverflow.com/questions/13093126/insert-unicode-character-into-javascript) – Jukka K. Korpela Apr 03 '14 at 04:47
  • Try this: `'\u{2191}'` – Piotr Kowalski Nov 04 '17 at 22:04

3 Answers3

5

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

ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
  • or maybe `'\x8593'`but I kind of doubt it. – ThorSummoner Apr 03 '14 at 04:34
  • Thank you - what worked was actually `"\u2191"` your answer got me the closest and trial and error got me the rest of the way. – lwalden Apr 03 '14 at 04:44
  • 1
    @ThorSummoner No, the `\x` prefix is used for the so-called [hexadecimal escape sequences](http://mathiasbynens.be/notes/javascript-escapes#hexadecimal) in JavaScript, and those only accept two digits (not four). So you have to use the [Unicode escape sequence](http://mathiasbynens.be/notes/javascript-escapes#unicode) which accepts four digits, as in your post. – Mathias Bynens Apr 04 '14 at 07:46
2

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;.

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
0

Try using this in your html: &uparrow;

3abqari
  • 228
  • 1
  • 2
  • 10