July 5, 2010
jQuery conflict with body onload event
Question by Evgeny
I have a strange conflict in my code.
I have a function that called from body onload:
var someGlobalVar=new SpecialType();
function OnBodyLoad()
{
someGlobalVar.Bind();
}
But when I include jQuery 1.4.2 in my project I get an error that someGlobalVar is undefined.
Why is the global variable undefined now, and what ways are there to fix it?
Answer by Kevin
Just a side note.
// DOM Ready
$(document).ready(function() {});
// When the page has completely loaded
<body onload="someFunction()">
Answer by Starx
Why don’t you use jQuery’s load event?
$(window).load(function() {
functiontoexecute();
});
It is simple, and it is easy.