john
john

Reputation: 1273

how to use unicode character in javascript

For a js click function to View and Hide some comments, i use this unicode ▼ and ▲ (Arrow up and arrow down)

$('.toggle-<?php echo $comment_id; ?>').click(function(){
    $(this).text($(this).text() == 'Hide replies &#9650;' ? 'View replies &#9660;' : 'Hide replies &#9650;'); 

But it shows me literally the code instead of the arrow.

So how i need to use the code in the script above?

Upvotes: 0

Views: 390

Answers (1)

Carsten Massmann
Carsten Massmann

Reputation: 28196

The syntax &#<num>; is html, therefore it needs to be entered as such, using $(...).html('&#9660 ...') instead of $(...).text('&#9660 ...').

The following should work:

$(this).html($(this).text().substr(0,4) == 'Hide' ? 'View replies &#9660;' : 'Hide replies &#9650;'); 

Upvotes: 2

Related Questions