I want to make something like library in JS. If table has a class=”aClass” I want to automatically modify some of it’s elements using JS.
I tried this way:
window.onLoad = LoadSetup();
function LoadSetup()
{
tables = document.getElementsByTagName("table");
alert(tables.length); // it's 0 though there are is one in the document
}
But i seems that this function runs before loading html. How to fix this?
Two problems:
onloadneeds to be all lower case. Rather than binding an event handler towindow.onload, you are adding a custom property towindowofonLoad.onloada reference to the function. Omit the parentheses. With the parens, you are calling the function immediately, and assigning its return value towindow.onLoad.Try this: