Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How to determine if HTML text is using an icon font?

I am making something similar to this browser extension that substitutes certain phrases with silly equivalents throughout a webpage. I have read replace words in the body text but one problem that every answer shares is that they also break icon fonts. To see what I mean, go to Google Font's Material Icons demo page and edit the text content inside a <span> with an icon. I found this recommendation by the W3C that font icons be identified with the ARIA role="img" attribute. But this depends on proper implementation by the developer which the demo page seems to lack.

I came up with the following kludge which appears to work for the pages I've tested it on. I would think that the probability of there existing an icon font without "icon" in its name is lower than that of developers setting the role attribute correctly, but clearly both approaches are very fragile and I am wondering if there is something more robust.

window.getComputedStyle(node).getPropertyValue('font-family').toUpperCase().includes('ICON')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This isn't 100% infallible, but one would sincerely hope that in any occurrence of an icon font, the element will have a class attribute and somewhere in that class attribute the letters i, c, o and n will be found consecutively and in that order.

In which case, for any textNode you can run the following check:

if ((myTextNode.parentNode.hasAttribute('class') === false) || (myTextNode.parentNode.className.includes('icon') === false)) {

  // REPLACE TEXT
}

But as you've already recognised, this does require the implementor actually using the word icon somewhere in the className of the element containing the textNode.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!