Skip to content

SVG framework function: scan

This tutorial is part of Iconify SVG Framework functions tutorial.

Function scan() scans document for icon placeholders and replaces placeholders with icons.

SVG framework automatically watches document.body and scans DOM after every change, so no need to use this function after you are changing DOM.

When to use this function:

If you want SVG framework to watch custom root element for changes, do not use this function, use observe() instead. This function stops watching element when all placeholders have been replaced, observe() continues to watch element until you tell it to stop using stopObserving().

Usage

Function has the following optional parameter:

  • root, HTMLElement. Element to scan. If missing, function will scan all watched root elements.

Example

jsconst node = document.createElement('div');
node.innerHTML =
   'Home icon: <span class="iconify" data-icon="mdi:home"></span>';
Iconify.scan(node);

Notes

  • Function might not replace placeholders immediately. If an icon has not been loaded, SVG framework will asynchronously load icon from Iconify API, then scan DOM again and replace placeholders.
  • Do not use placeholder as root element. Function checks only child elements, not root element.

Released under the Apache 2.0 License.