#how to reach edit button (javascript)
1 messages · Page 1 of 1 (latest)
I can't see all of your code, but from the screenshot it looks like the querySelectorAll bit and on from there is outside of the show function. I assume it's just in the javascript file at the main level?
it isabsolutely empty
does the querySelectorAll not read edit buttons autside of show function?
it does, it just matters when it runs
here is other part of my code
When you define a function, that code doesn't run until you call the function, but outside of functions javascript is executed line by line from top to bottom as soon as it's loaded.
What's happening here is that the variables are set, that ascending block is run, then window.onload is set to call show() when it's fully loaded, the show function is declared (but not run), then the querySelectorAll runs.
Because the window.onload hasn't fired yet, show hasn't run yet, so the class="edit" buttons don't exist yet in the DOM, which means querySelectorAll can't find them yet. When the entire script has run, and the browser fires the onload event, then the edit buttons are added to the DOM, but the querySelectorAll has already run
you should be able to move this code into the onload function, after show();. That would make sure that the buttons exist by the time the querySelectorAll runs and needs to find them
i can see now 🙂