views:

128

answers:

4

I have the following JQuery code:

$(this).text('Options ▴');

However, the ascii code isn't showing up on my web page. All that shows up is on the webpage is Options ▴.

What am I doing wrong?

+2  A: 

&#x25B4 is definitely not ascii (ascii's a character code that runs from 0 to 127...!-) -- it seems to be a high-page unicode character. What char encoding is your page using? With something "universal" like utf-8, unicode characters should show up... if the browser has them in its font, of course. With other encodings, such characters might just be impossible to transmit and show.

Alex Martelli
It's an arrow triangle. The crazy thing is that if I do within HTML "Options ▴", the unicode character displays. But if I do my code via JavaScript, the unicode does NOT display
JGreig
+2  A: 

Use the .html() method instead of .text().

The whole point of .text() method is to make the text appear exactly as it's in the string, with all tags and entities.

Fyodor Soikin
Thanks, works..
JGreig
Would you be so kind to accept the answer then?
Fyodor Soikin
A: 

You can try this:

$(this).html('Options ▴');

Output:

Options ▴

If you want to test it online you can check out this website. (I liked it very much)

Krunal
A: 

If you use a unicode escape ('\u25B2') instead of the html escape character, you can use the .text method.

Some users will not have a font that will display either version.

kennebec