views:

103

answers:

3

I have ,

`<span class="icon">&#9658;</span>`

in Jquery I did,

$(this).html('&#9660;');

and tried $(this).replaceWith('&#9660;'); too.

but it displays '&#9660;' instead of converting it to a html icon like ▼.

thanks

+3  A: 

This works just fine: $("span.icon").html('&#9660;');

Josh Stodola
+1  A: 

Why not just hardcode the unicode literal?

$('<span>').text('▼').appendTo('body')

You have to make sure you're serving the js file as UTF-8 though.

Edit: .html() should also work fine..

$('<span>').html('&#9660;').appendTo('body')

Make sure the this reference is pointing to the correct object, you can do var foo = this; before switching function scope.

meder
A: 

What is this referring to? I think you might not be the span tag. Here's a working example.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
<head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;

    <script type="text/javascript">
    $(function() {
        $('span.icon').html('&#9660;');
    });
    </script>
</head>
<body>

<span class="icon">&#9658;</span>

</body>
</html>
Darin Dimitrov