Skip to content

Commit

Permalink
Use more specific selector for name links (#29679)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
silverwind authored Mar 8, 2024
1 parent 82e102f commit baeb251
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion web_src/js/markup/anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function initMarkupAnchors() {
if (!href.startsWith('#user-content-')) continue;
const originalId = href.replace(/^#user-content-/, '');
a.setAttribute('href', `#${encodeURIComponent(originalId)}`);
if (document.getElementsByName(originalId).length !== 1) {
if (a.closest('.markup').querySelectorAll(`a[name="${originalId}"]`).length !== 1) {
a.addEventListener('click', (e) => {
scrollToAnchor(e.currentTarget.getAttribute('href'), false);
});
Expand Down

0 comments on commit baeb251

Please sign in to comment.