Skip to content

Commit

Permalink
Add a check for non-empty id before trying to find it in the document
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
  • Loading branch information
martin-g committed Nov 29, 2024
1 parent 2dca014 commit 15ece24
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions source/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
let closest;
// Get the last part of the URL after the # symbol - should match the div id to display
let id = window.location.hash.substring(1);
let elem = document.getElementById(id);
if (elem != null) {
// Get the closest "details" element and open it
closest = elem.closest("details");
if (closest) closest.open = true;
if (id) {
let elem = document.getElementById(id);
if (elem != null) {
// Get the closest "details" element and open it
closest = elem.closest("details");
if (closest) closest.open = true;
}
}
</script>

Expand Down

0 comments on commit 15ece24

Please sign in to comment.