Skip to content

Replace $(window).load with $(window).on("load") #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace $(window).load with $(window).on("load")
  • Loading branch information
yesthatguy authored Nov 30, 2016
commit 765ae6b50e02b1464f121810c19d56db066c5d7e
8 changes: 4 additions & 4 deletions page/using-jquery-core/document-ready.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"level": "beginner"
}</script>

A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside `$( document ).ready()` will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside `$( window ).load(function() { ... })` will run once the entire page (images or iframes), not just the DOM, is ready.
A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside `$( document ).ready()` will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside `$( window ).on( "load", function() { ... })` will run once the entire page (images or iframes), not just the DOM, is ready.

```
// A $( document ).ready() block.
Expand Down Expand Up @@ -32,10 +32,10 @@ function readyFn( jQuery ) {

$( document ).ready( readyFn );
// or:
$( window ).load( readyFn );
$( window ).on( "load", readyFn );
```

The example below shows `$( document ).ready()` and `$( window ).load()` in action. The code tries to load a website URL in an `<iframe>` and checks for both events:
The example below shows `$( document ).ready()` and `$( window ).on( "load" )` in action. The code tries to load a website URL in an `<iframe>` and checks for both events:

```
<html>
Expand All @@ -46,7 +46,7 @@ The example below shows `$( document ).ready()` and `$( window ).load()` in acti
console.log( "document loaded" );
});

$( window ).load(function() {
$( window ).on( "load", function() {
console.log( "window loaded" );
});
</script>
Expand Down