admin管理员组文章数量:1244389
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?
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?
Share Improve this question edited May 23, 2017 at 11:44 CommunityBot 11 silver badge asked May 2, 2015 at 4:28 PekkaPekka 1,1152 gold badges11 silver badges17 bronze badges 4-
1
You have to use quotes around that.
text('✔')
– user4698813 Commented May 2, 2015 at 4:29 -
tried it mate what appeared is the text
✔
not a check mark. I want the check mark to appear not the text – Pekka Commented May 2, 2015 at 4:30 -
Aaah yeah, then use
html
. – user4698813 Commented May 2, 2015 at 4:31 - 1 check jsfiddle/2bagqtsv/1 – ketan Commented May 2, 2015 at 4:32
4 Answers
Reset to default 6Use .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('✔');
What I would do is:
$('#spanid').addClass('check');
and add css;
.check:after {
content: '(what ever the code for the check mark is)';
}
Alternatively, you could create checkmark with String.fromCharCode
:
$('#spanid').text(String.fromCharCode(10004));
Try
$('#spanid').html ('✔');
instead of text()
. The text function escapes the string.
本文标签: javascriptUsing jQuery to add a ✔ tick mark in spanStack Overflow
版权声明:本文标题:javascript - Using jQuery to add a ✔ tick mark in span - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740217055a2243064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论