Icon not showing in simple JavaScript
See original GitHub issueI am trying to use iconify but I cannot. Is this correct? Nothing shows for me. What should I do with Iconify
after import? The documentation is very vauge.
import Iconify from '@iconify/iconify';
export function createIcon(iconName) {
const icon = document.createElement("div");
icon.innerHTML = `
<span class="iconify" data-icon="${iconName}"></span>
`
return icon
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Why is this icon not showing up? - HTML-CSS
Does anyone know why this icon isn't showing up? Here's the html code: <head> <link rel="stylesheet" ...
Read more >The icon does not appear in the small interfaces even though ...
you are missing Fontawesome JS file in your project. Add in your <head> link to all.min.js from Fontawesome and your icons will be...
Read more >Troubleshooting | Font Awesome Docs
The icon I want to use is missing or not showing up? · Is the icon you're trying to use available in the...
Read more >Icons Tutorial - W3Schools
How To Add Icons. To insert an icon, add the name of the icon class to any inline HTML element. The <i> and...
Read more >How to hide “Image not found” icon when source image is not ...
JavaScript and jQuery can be used to hide the “Image Not Found”icon when the image is not found. The basic idea is to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There are big changes in beta 4 that has just been released, which can solve your problem differently. You don’t really need it, but I think it is worth mentioning if it helps anyone else to solve similar issue.
In original message you wanted Iconify to replace icons in node that isn’t attached to DOM. It wasn’t possible in old version because Iconify scanned only body. Now it is possible.
Method 1 can scan node once, do not watch it for changes:
Iconify.scan(node)
.Method 2 will scan node and will observe it for changes:
Iconify.observe(node)
. To remove observer, useIconify.stopObserving(node)
.I forgot that in version 2 I’ve already added function similar to createElement: renderSVG
It will return null if icon does not exist, which would usually complicate things a bit, however because you also want offline usage, this is not an issue because icon should always exist.
If you want to make sure an element is always returned, even when icon is missing, use this:
As for offline use, best option is to create a bundle.
In your test files I’ve made
build-iconify.js
in root directory that createslib/iconify-bundle.js
:Install
@iconify/json
as dev dependency, runnode build-iconify
.Then I’ve replaced
lib/icon-service/iconify.js
with this:Bundle is 7.35mb in size, which I think is reasonable considering that it includes multiple icon sets.
In
build-iconify.js
change icon sets list as needed. Because you have prefixes for icon sets that are sometimes different from ones used in Iconify, I’ve made variableiconSet
an object, where key is Iconify prefix, value is prefix you want to use.Few notes about icon sets: