oguh43
oguh43

Reputation: 85

Javascript wrongly decodes unicode

I'm trying to get an id of a font-awesome icon. It is located in ::before style. When i use

window.getComputedStyle(document.querySelector("[id='5']"), '::before').getPropertyValue('content')

to get it, instead of "\f458", "\"\"" is returned.

I assume that JavaScript is trying to convert the code into a char but fails. Is there any way to prevent this?

Upvotes: 1

Views: 49

Answers (1)

Peter Badida
Peter Badida

Reputation: 12169

The decoding works, the problem is the font. If there's no match for this character in a font you use, it'll be mangled or in the form of the unicode value in a box.

Since it's in the private area, depending on the font it might be resolved into a glyph or be mangled or be just empty/space.

Checking in the Font Awesome Cheatsheet it looks like a an icon for quidditch.

Perhaps there's a text to image/svg map somewhere on the internet (and if not, then just copy-paste localy and create one) which you might use if the font itself isn't good or you are decoding in a problematic environment (can't install fonts, etc).

Upvotes: 3

Related Questions