+ 1
Window.Onload not working on function?
4 ответов
+ 6
Icon Mikky
When you call function from a html event then no need to write function inside window.onload function because when event will be occur then function will be call.
You have 2 button or more button doesn't matter.
+ 3
When document is loaded, your javascript code will run, then when you try to click on button it will search for this function and it wont find it.
We dont use window onload in such way, if you will add event listener from javascript then you need to add this inside window.onload.
window.onload allow you to access elements after they are rendered to screen (in your code you dont need this), same as your script is placed at bottom of html page, right before </body>
Check this code to understand better how it works:
https://code.sololearn.com/WH0xv85NMI89/?ref=app
+ 1
Somehow tricky but thanks
What if i have two button ?
+ 1
you assign different variables to your buttons and add corresponding event listeners for each.