What is the relevence of window.onload function.
The scripting we are doing here inside the function windows.onload can also be done without it I guess
Window.onload function
yes you can do it without onload, but there will be no surety that the script will work
as there may be problem with loading of element or slow loading, in those cases without onload you script starts working without checking if the elements are present on page or not
Read more about it here
https://www.w3schools.com/jsref/event_onload.asp