admin管理员组文章数量:1317906
I am returning special characters (specifically °
) in JavaScript/jQuery, but it is not converting the entity to the desired character in the display. How can I display the degree sign correctly?
It must be simple; what am I missing? I have checked decodeURL
, but it does nothing.
Demo fiddle
The HTML:
<p>Try to give answer is: </p>
<div id="target"></div>
<p>But should look like:</p>
<div> 5 °C</div>
And the Javascript with jQuery:
$('#target').text('5 °C');
Output:
I am returning special characters (specifically °
) in JavaScript/jQuery, but it is not converting the entity to the desired character in the display. How can I display the degree sign correctly?
It must be simple; what am I missing? I have checked decodeURL
, but it does nothing.
Demo fiddle
The HTML:
<p>Try to give answer is: </p>
<div id="target"></div>
<p>But should look like:</p>
<div> 5 °C</div>
And the Javascript with jQuery:
$('#target').text('5 °C');
Output:
Share Improve this question edited Jan 29, 2021 at 2:17 Abel Callejo 15k12 gold badges76 silver badges92 bronze badges asked May 1, 2015 at 16:05 SablefosteSablefoste 4,1923 gold badges40 silver badges60 bronze badges 1
- possible duplicate of Unescape HTML entities in Javascript? – user1596138 Commented May 1, 2015 at 16:15
2 Answers
Reset to default 8To see the interpreted character entity you need to use html()
:
$('#target').html('5 °C');
Updated fiddle
Try this:
$('#target').html('5 °C');
text
function escapes the html
characters so you get what you see.
本文标签: javascriptAppending a special character with jQuery not workingStack Overflow
版权声明:本文标题:javascript - Appending a special character with jQuery not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742030758a2416397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论