Skip to content

Commit baeb251

Browse files
authored
Use more specific selector for name links (#29679)
Followup #29305. As per discussion in #29666 (comment), make this selector only search in the current `.markup` document, as there can be multiples displayed at the same time. @DanielMatiasCarvalho maybe you can review.
1 parent 82e102f commit baeb251

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

web_src/js/markup/anchors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function initMarkupAnchors() {
3939
if (!href.startsWith('#user-content-')) continue;
4040
const originalId = href.replace(/^#user-content-/, '');
4141
a.setAttribute('href', `#${encodeURIComponent(originalId)}`);
42-
if (document.getElementsByName(originalId).length !== 1) {
42+
if (a.closest('.markup').querySelectorAll(`a[name="${originalId}"]`).length !== 1) {
4343
a.addEventListener('click', (e) => {
4444
scrollToAnchor(e.currentTarget.getAttribute('href'), false);
4545
});

0 commit comments

Comments
 (0)