How to print special characters using jquery?

I am developing a web page in Slovak. To use certain language characters, such as á or ž, I use this HTML code:

<html lang="sk"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> 

Now it works as expected, but only when I hardcode this text into an html file.

As soon as I use jquery to print them, it breaks and these characters are not displayed correctly.

 $("#myDiv").html("áž"); 

Should I specify something in jquery or is there any other way to overcome this problem?

+7
javascript jquery html
source share
3 answers

You can pass the numeric object for this character to the html () function to achieve this,

Try a sample,

 $('body').html('&#926;'); 

Demo

+6
source share

I think you can use some tricks here

try it

 $("#myDiv").html($("<div>").html("áž").text()); 

Or just try this

 $("#myDiv").text("áž"); 
+4
source share

You can do the following very easily. Use any special character u want

 $("#mydiv").text("*&^&*^*&^*"); 

Here is a demo

+2
source share

All Articles