This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes window.onload in self invoking function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "window.onload in self invoking function" Watch "window.onload in self invoking function" New topic

window.onload in self invoking function

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I have a self invoking function with a window.onload in it. But the window.onload is not really called after windows is loaded. Often, myBtn returns null as the chrome-debugger says

"Uncaught TypeError: Cannot set property 'onclick' of null".

Why is that so? How can I solve that?

Using jquery and this script returns the same error:

I have put the script into the head-element.

I know, that document.ready will run immediately after DOM is built.
Self-invoking functions will run instantly - but window-onload should, normally should run after dom is built.
But this is not the case. Why?
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
In both cases it means that you do not have a single element on the page with that id.

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I was so blind! You are right!

I am using jsf with templating and had something like this <ui:remove>

within the tags which was called by javascript.

So that was the reason.

Thanks !!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: window.onload in self invoking function
jQuery in Action, 3rd edition