MarMan29 MarMan29 - 1 year ago 83
Javascript Question

Test for special & html code

I set a span using:

<span id=\"xxx\">&#9656;</span>

Can someone tell me why the following test doesn't work:

if ($("#xxx").text() == "&#9656;")

Answer Source

If you don't want to use the other answer that make a direct symbol condition $("#xxx").text() == "▸" and you want to check the span text &#9656;, you could use .charCodeAt(0) to get the special symbole number then add &# and ; in your condition :

var special_symbol_number = $("#xxx").text().charCodeAt(0);

if ( "&#"+special_symbol_number+";" === "&#9656;")

Or you could check just with special symbol number as :

if ($("#xxx").text().charCodeAt(0) === '9656')

Hopet this helps.

if ($("#xxx").text().charCodeAt(0) === '9656')
<script src=""></script>
<span id="xxx">9656</span>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download