3

I would like to put unicode in the data-content attribute using JQuery so as to use it for pseudo element content, but I can't find the right format. How do you display unicode? The fallowing just displays ▼.

a::after
{
    content: attr(data-content);
}
<a href="...">...</a>
$("a").attr ("data-content", "&#x25BC;");
Ava
  • 2,038
  • 3
  • 23
  • 45

1 Answers1

5

Insert in this format, using the \u that, in Javascript, denotes an Unicode number inside a string literal

$("a").attr ("data-content", "\u25BC");

From MDN Unicode escape docs:

You can use the Unicode escape sequence in string literals, regular expressions, and identifiers. The escape sequence consists of six ASCII characters: \u and a four-digit hexadecimal number. For example, \u00A9 represents the copyright symbol. Every Unicode escape sequence in JavaScript is interpreted as one character.

$("a").attr ("data-content",  "\u25BC");
a::after
{
    content: attr(data-content);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


<a href="...">...</a>
LcSalazar
  • 16,524
  • 3
  • 37
  • 69