So I have this code:
var bindAll;
bindAll = function ()
{
$(\'#somediv\').bind(\'mouseover\', function(){do something});
};
var init;
init = function ()
{
You aren't passing init to $(document).ready
, you're passing whatever init returns.
Try this:
$(document).ready(init);
Explanation:
When you were trying to pass the function, you were actually running it. At the time of you running it, the DOM wasn't ready, so the bindings to the element didn't take place, because it didn't exist.
When you did the timeout, it worked because it took less then one second for the DOM to finish, which means by the time it gets run, the element is there, so it can bind the event.