How to print special characters with jquery?

I am designing web page in slovak language. To be able to use meantioned language special characters such as á or ž, I am using 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 hard code that kind of text into html file.

As soon as I use jquery to print them it breaks down and those characters are not correctly shown.

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

Am I supposed to specify something in jquery or is there another way to overcome this problem?

Upvotes: 7

Views: 6427

Answers (3)

TheDean
TheDean

Reputation: 285

It is quite Easy you can do the following Use any special Character u want

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

Here is the Demo

Upvotes: 2

nrsharma
nrsharma

Reputation: 2562

I think you may be use some tricks here

Try this

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

Or simply try this

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

Upvotes: 4

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

You can pass the numeric entity for that character into the html() function to achieve that,

Try a sample,

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

DEMO

Upvotes: 6

Related Questions