Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 569
Tural Ali Avatar asked Dec 24 '11 02:12

Tural Ali


1 Answers

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/

like image 195
Pencho Ilchev Avatar answered Nov 13 '22 13:11

Pencho Ilchev