Pekka Pekka - 6 months ago 34
jQuery Question

Using jQuery to add a ✔ tick mark in span

From this question I learned that the check mark is the code

✔ (0x2714 [HTML decimal: ✔])
. I know that you add text to a span using jQuery by doing
$('#spanid').text(texthere);
. I want to add the check mark to the span.

I did it like

$('#spanid').text(✔); //This errors on the `&`
$('#spanid').text(#10004); //This results in `Unexpected token ILLEGAL


What is the correct way of doing this?

Answer

Use .html(). Also, enclose the value in quotes.

$('#spanid').html('✔');

.text() will convert the input to text string. .html() converts to HTML string/content and the character encoded can be seen.

Fiddle Demo

or if you already have the character , .text() would work;

$('#spanid').text('✔');
Comments