Skip to content

Commit

Permalink
Fix of stylesheet load events example (#32557)
Browse files Browse the repository at this point in the history
The tag ``link`` should go before the ``script``, otherwise the script runs before ``HTMLLinkElement`` is created and thus fails.
  • Loading branch information
juliyvchirkov authored Mar 5, 2024
1 parent 8a8e2a0 commit 0721ce3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions files/en-us/web/html/element/link/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ this resource will then only be loaded if the media condition is true. For examp
You can determine when a style sheet has been loaded by watching for a `load` event to fire on it; similarly, you can detect if an error has occurred while processing a style sheet by watching for an `error` event:

```html
<link rel="stylesheet" href="mystylesheet.css" id="my-stylesheet" />

<script>
const stylesheet = document.querySelector("#my-stylesheet");
const stylesheet = document.getElementById("my-stylesheet");
stylesheet.onload = () => {
// Do something interesting; the sheet has been loaded
Expand All @@ -369,8 +371,6 @@ You can determine when a style sheet has been loaded by watching for a `load` ev
console.log("An error occurred loading the stylesheet!");
};
</script>

<link rel="stylesheet" href="mystylesheet.css" id="my-stylesheet" />
```

> **Note:** The `load` event fires once the stylesheet and all of its imported content has been loaded and parsed, and immediately before the styles start being applied to the content.
Expand Down

0 comments on commit 0721ce3

Please sign in to comment.