Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 434
Pekka Avatar asked May 02 '15 04:05

Pekka


2 Answers

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('✔');
like image 63
Shaunak D Avatar answered Oct 07 '22 09:10

Shaunak D


What I would do is:

$('#spanid').addClass('check');

and add css;

.check:after {
  content: '(what ever the code for the check mark is)';
}
like image 27
Flo Avatar answered Oct 07 '22 10:10

Flo