No description
Find a file
2024-10-29 10:31:17 +01:00
src fixes for child nodes 2024-10-29 10:31:17 +01:00
package.json fixes for child nodes 2024-10-29 10:31:17 +01:00
README.md bring some basic documentation 2024-05-26 21:22:30 +02:00

now and later

You know the situation: you create some HTML nodes dynamically. But the new elements behave not the way, you expected, because you enriched the functionality with javascript.

These newly created elements did not exist, when your initializers ran, so they got not initialized.

But often it is hard to have your initialize functions available - or maybe they realy do not belong to the functionality, which created them.

To help with exactly this situation, there is nowAndLater.

So instead of spreading your initializer calls everywhere, you use nowAndLater from the beginning. And all elements which arive later to the party, will handled exactly like those nerds, which were there from the very beginning.

Usage is as follows:

nowAndLater('a.submit-form', (a) => {
    a.addEventListener('click', () => a.closest('form').submit())
})

The function takes exactly two arguments: a selector, which will used to identify the elements to work with and a callback, which will be called for each element, that matches this selector. This will happen in the moment you call the nowAndLater function - and everytime a new DOM element arrives, which matches your selector.