If I have markup like this:
<div id="foo"></div>
and I want to detect later whether div#foo still contains that same character entity, I'd like to be able to do so by comparing it to 
rather than to
(which in my code base is rather obtuse for maintenance purposes).
I've tried things like this (using jQuery):
console.log($('<textarea />').html($('#foo').html()).val());
But that seems to still output the nice little square "what you talkin' 'bout" character rather than the desired 
.
I'm open to plain JavaScript or jQuery-specific solutions.
You can use a Unicode entity in JavaScript. For example:
(HTML: <div id='foo'></div>
)
JavaScript:
console.log($('#foo').html().charCodeAt(0).toString(16));
//=> f067
console.log($('#foo').html().indexOf('\uf067'));
//=> 0
来源:https://stackoverflow.com/questions/25408731/detect-whether-html-element-contains-a-specific-character-entity