From 83bcc3c00f0d1fb166324f9f3ac8f4a9f3eee323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Poupard?= Date: Tue, 18 May 2021 07:31:15 +0200 Subject: [PATCH] docs(cheatsheet): fix JS errors in `setActiveItem()` (#34011) --- site/content/docs/5.0/examples/cheatsheet/cheatsheet.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/site/content/docs/5.0/examples/cheatsheet/cheatsheet.js b/site/content/docs/5.0/examples/cheatsheet/cheatsheet.js index 541cf9350a..0a50258b92 100644 --- a/site/content/docs/5.0/examples/cheatsheet/cheatsheet.js +++ b/site/content/docs/5.0/examples/cheatsheet/cheatsheet.js @@ -25,8 +25,8 @@ toast.show() }) - // Disable empty links - document.querySelectorAll('[href="#"]') + // Disable empty links and submit buttons + document.querySelectorAll('[href="#"], [type="submit"]') .forEach(function (link) { link.addEventListener('click', function (event) { event.preventDefault() @@ -41,6 +41,11 @@ } var link = document.querySelector('.bd-aside a[href="' + hash + '"]') + + if (!link) { + return + } + var active = document.querySelector('.bd-aside .active') var parent = link.parentNode.parentNode.previousElementSibling