I want to update the content of a span like so:
$('#myElement').text('£' + parseFloat(myPrice));
But the HTML does not render the £
correctly when updated. There are other instances where I want to use a different symbol as well.
Is there a way around this?
You need to use the html()
method as text()
encodes the value. Try this:
$('#myElement').html('£' + parseFloat(myPrice));
$(function(){ var myPrice = "403"; $('#price').html('£' + parseFloat(myPrice)); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> <p id="price"></p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.