From 22f75ca2e328ad232dd2afafd15dc0c79a908410 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 5 May 2020 21:42:58 +0200 Subject: [PATCH] enforce element check on scrollspy target --- js/src/scrollspy.js | 2 +- js/tests/unit/scrollspy.js | 2 +- site/docs/4.4/components/scrollspy.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 2c7c8a1dc813..bf546a258656 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -157,7 +157,7 @@ class ScrollSpy { ...typeof config === 'object' && config ? config : {} } - if (typeof config.target !== 'string') { + if (typeof config.target !== 'string' && Util.isElement(config.target)) { let id = $(config.target).attr('id') if (!id) { id = Util.getUID(NAME) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index c311c8423754..6f5c92caba5a 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -127,7 +127,7 @@ $(function () { .show() .find('#scrollspy-example') .bootstrapScrollspy({ - target: document.getElementById('#ss-target') + target: document.getElementById('ss-target') }) $scrollspy.one('scroll', function () { diff --git a/site/docs/4.4/components/scrollspy.md b/site/docs/4.4/components/scrollspy.md index 43443e7fbea6..eb5b4ba6ff42 100644 --- a/site/docs/4.4/components/scrollspy.md +++ b/site/docs/4.4/components/scrollspy.md @@ -314,7 +314,7 @@ Options can be passed via data attributes or JavaScript. For data attributes, ap target - string + string | jQuery object | DOM element Specifies element to apply Scrollspy plugin.