#how to reach edit button (javascript)

1 messages · Page 1 of 1 (latest)

leaden igloo
#

i creat tr for each element of array and add this tr inside of "tbody" then i want to reach all edit buttons inside of all tr but when i try this it return nothing it does not see my edit buttuns. what cause that is there any idea?

#

when i read tbody edit buttons are there but can not reach them why?

bleak saddle
#

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?

leaden igloo
#

it isabsolutely empty

leaden igloo
bleak saddle
#

it does, it just matters when it runs

leaden igloo
#

here is other part of my code

bleak saddle
#

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

leaden igloo
#

i can see now 🙂