How to declare const and find element on the page, that was dynamically rendered after fetch?
Let's say I have navigation with first element hard coded in html and the rest dynamically rendered after fetch.
If I declare it at the beginning of the script:
const navItems = document.querySelectorAll('#nav li');
it only finds the first one (hard coded). I understand why this is happening, but I'm not sure what to do with this. I need all of navItems in other functions and it's not working.
If I declare it in the last then
of the fetch function. It works, but I'm not sure it's a correct way. It doesn't look 'pretty'.