Back to the article · Zurück zum Artikel (Deutsch)
Example 02: A fragment and the excerpt the article shows
Showing only an excerpt
A button and a script. The article shows only the handler region of this fragment, the page runs all of it and lists the complete source at the bottom.
How to try it
- Click "Count" a few times. The "Console output" box and the console of the developer tools (F12, Cmd+Opt+I on a Mac) show one line per click.
- Compare the source at the bottom with the article: the lines with
#regionare not displayed there.
console.log() and errors on this page, the same text as in the developer toolsclicks: 1 clicks: 2 clicks: 3
After three clicks.
Live example
Source
<button id="count" type="button">Count</button>
<script>
// Everything outside the region below runs on this page, but the article
// shows only the region.
let clicks = 0;
document.getElementById('count').addEventListener('click', () => {
clicks += 1;
console.log('clicks:', clicks);
});
</script>