Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Last active June 9, 2021 16:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prof3ssorSt3v3/068de390c81454024a8e62e2da684e4b to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/068de390c81454024a8e62e2da684e4b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Details and Summary Elements</title>
<style>
summary::-webkit-details-marker {
color: red;
}
::marker {
color: gold; /* FF */
}
</style>
</head>
<body>
<main>
<p>
<code>details &amp; summary elements</code>
</p>
<details>
<summary>Heading</summary>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ab molestias
maiores ipsa qui totam, ea unde quisquam tenetur? Voluptatum magni
magnam alias eaque laborum, dolore praesentium veniam molestias harum
hic.
</p>
</details>
<script>
document.addEventListener("DOMContentLoaded", () => {
let p = document.querySelector("main>p");
p.addEventListener("click", (ev) => {
console.log("paragraph clicked");
let det = document.querySelector("details");
if (det.hasAttribute("open")) {
// det.removeAttribute("open");
det.open = false;
} else {
// det.setAttribute("open", "open");
det.open = true;
}
});
});
//To deal with opening the detail summaries for printing can be done like this
window.addEventListener('beforeprint', (ev) => {
let det = document.querySelector('details');
det.setAttribute('open', 'true');
});
window.addEventListener('afterprint', (ev) => {
let det = document.querySelector('details');
det.removeAttribute('open');
});
</script>
</main>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment