From 15ece24bf2cc256461fbc8f4d9e8d8968bb9163e Mon Sep 17 00:00:00 2001 From: Martin Tzvetanov Grigorov Date: Fri, 29 Nov 2024 09:43:54 +0200 Subject: [PATCH] Add a check for non-empty id before trying to find it in the document Signed-off-by: Martin Tzvetanov Grigorov --- source/templates/layout.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/templates/layout.html b/source/templates/layout.html index b9b181b..7352d00 100644 --- a/source/templates/layout.html +++ b/source/templates/layout.html @@ -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; + } }