Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery .bind() and/or .ready() not working

So I have this code:

var bindAll;
bindAll = function ()
{
    $('#somediv').bind('mouseover', function(){do something});
};

var init;
init = function ()
{
    bindAll();
    ...
};

$(document).ready(init());

and it does not work. But if I put the bind on a timer by replacing:

bindAll();

with

tt = setTimeout('bindAll()', 1000);

It suddenly works perfectly. What!??

like image 818
providence Avatar asked Dec 10 '25 09:12

providence


1 Answers

jQuery ready expects a handler, not a function call.

// $(document).ready(init()); <-- Not working
$(document).ready(init); <-- Working!

Working example at: http://jsfiddle.net/marcosfromero/Qwghb/

like image 58
marcosfromero Avatar answered Dec 12 '25 23:12

marcosfromero