Question

im creating a emoticon js script and i cant seem to get the character code for to work ive tried ♥ as the character code but dosen't work any help would be help ful

my script

jQuery.fn.emotion_func = function(icon_folder) {
var emotion_locate =  "emotions";
var key_stroke = { ....
         "heart": Array("♥")//it dosent work 
                   ....
             };

function emotion_func(html){
for(var emotion in key_stroke){
    for(var i = 0; i < key_stroke[emotion].length; i++){
        var key = new RegExp(key_stroke[emotion][i],"g");//replace all occurenced
        html = html.replace(key,"<span style=\"background-image:url("+emotion_locate+"/"+emotion+".png); \" title="+emotion+" /></span>");
                }
            }
            return html;
        }
        return this.each(function(){
            $(this).html(emotion_func($(this).html()));
        });
    };

Any Help would be appreciated

Also note that im using html 5

Sorry but only @hwnd's answer worked for me

Was it helpful?

Solution 2

The term you're looking for is "entity." There are only a few named entities in HTML, but you can specify any character by its unicode ID:

&#x2665; will show up as: ♥

OTHER TIPS

You want to actually use the Unicode escape sequence \u2665 in your array for replacement.

var key_stroke = { 'heart': Array('\u2665') };

try

&hearts;

FIDDLE DEMO

HTML character codes

http://text-symbols.com/html/entities-and-descriptions/

OR

&#x2665;

DEMO FIDDLE

NOTE:dont forget to specify

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

and meta tag too

<meta http-equiv="Content-Type">

The black heart character has the unicode code 2665. In HTML unicode symbols can be output in the format prefix code suffix where prefix is always &#x and suffix is always ;. The character you want to output has the code 2665, so it can be done like this:

<p>character - &#x2665;</p>

The output is:

character - ♥

Because you are adding the character to a JavaScript array object (as literal), you need to use the unicode character representation (as @hwnd suggested) in JavaScript, by preceding the unicode character by \u (followed by the character code):

var a = Array('\u2665');
$('#panel').text(a[0]);

A reference to the unicode table containing all character codes: unicode character table.

Another HTML code for the heart sign: ♥

&#9829;

see it working in this JSFIDDLE DEMO

Red Heart Symbol Hex Code

If you want to use red heart variant you have to use two unicodes:
U+2764 - stands for heavy black heart
U+FE0F - is a variation selector

To insert ❤️ symbol in html type it's hexcode <p>&#x2764;&#xFE0F;</p>

You can see different Special and Math Symbols in HTML and JavaScript here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top