Skip to content

Commit a2172a0

Browse files
committed
Events - load
1 parent c689c16 commit a2172a0

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

Diff for: app.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
/*
2-
The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed without waiting for stylesheets, images, and subframes to finish loading.
2+
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images. This is in contrast to DOMContentLoaded, which is fired as soon as the page DOM has been loaded, without waiting for resources to finish loading
33
4-
window.addEventListener('DOMContentLoaded', function () {
4+
window.addEventListener('load', function () {
55
// code goes here
66
});
77
88
document.addEventListener.....
99
*/
1010

11-
// Global Event
12-
13-
// In simple terms, it looks for js once the dom content html is loaded
11+
window.addEventListener('load', function () {
12+
console.log('I will run second');
13+
const image = document.querySelector('img');
14+
console.log(image);
15+
});
1416
window.addEventListener('DOMContentLoaded', function () {
15-
const heading = document.querySelector('h1');
16-
console.log(heading);
17-
heading.style.color = 'red';
17+
console.log('DOMContentLoaded: I will run first');
18+
const image = document.querySelector('img');
19+
console.log(image);
1820
});

Diff for: index.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@
3838
margin-bottom: 1rem;
3939
}
4040
</style>
41-
<script src="./app.js"></script>
4241
</head>
4342
<body>
4443
<h1>Javascript</h1>
45-
44+
<img src="./mountains.jpg" alt="mountains" />
4645
<!-- Link to JS -->
47-
<!-- <script src="./app.js"></script> -->
46+
<script src="./app.js"></script>
4847
</body>
4948
</html>

Diff for: mountains.jpg

1.64 MB
Loading

0 commit comments

Comments
 (0)