Static vs dynamic targets
When creating a watcher with Hitbox, you provide a elements parameter (and possibly a targetElements parameter) that determines the elements you want to watch.
The type of this argument matters if you need to watch elements added to the DOM later:
If this element is a
Nodeor aNodeList(typically provided bydocument.querySelector()anddocument.querySelectorAll()functions), the targets will be static. This means that if you add an element after the initialization of the watcher, it won't be taken in account.If this element is a
stringrepresenting a CSS selector, the targets will be dynamic: if you add later an element matching the selector, it will be taken in account for collisions detection.
Last updated
Was this helpful?