Tural Ali
Tural Ali

Reputation: 23270

window.onload function issue

I've noticed some bug in window.onload function. (Maybe it's my wrong) The problem is when I used following simple function, it worked on all browsers but Chrome.

var name=$("#name");
window.onload = function(){
    name.fadeIn(500);
};  

Then just for interest, tried this one too:

var name;
window.onload = function(){
    name=$("#name");
    name.fadeIn(500);
};  

In all above cases, Chrome's dev tools gave me this error message:

Uncaught TypeError: Object [object Object] has no method 'fadeIn'

I've resolved this error with following code.

window.onload = function(){
    var name=$("#name");
    name.fadeIn(500);
};  

But now want some explanation, why didn't work first 2 piece of code?

Upvotes: 6

Views: 9519

Answers (1)

Pencho Ilchev
Pencho Ilchev

Reputation: 3241

I think that this might be down to a global variable called name. If you call name something different, name1, it works in chrome.http://jsfiddle.net/R2PuZ/1/

Upvotes: 4

Related Questions