Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

window.onload vs document.ready jQuery

I have a site with two columns. I want to have equal height on both using jQuery.

I'm trying to get the logo column height. I had:

$(document).ready(function() {
    alert($('#logo').height());
});?

and it didn't work. So I changed it to:

window.onload = function(){
    alert($('#logo').height());
}

And it's working. What is going on in here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

document ready is fired when the DOM has loaded, so information like height isn't available, unless it's explicitly declared.

window onload waits for the assets in the page to be completely loaded - so information such as height is now available.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...