Skip to content

Commit 45a90a7

Browse files
committed
Ensure only heading element text is used
1 parent d4f7016 commit 45a90a7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/js/02-on-this-page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
var links = {}
3030
var list = headings.reduce(function (accum, heading) {
3131
var link = document.createElement('a')
32-
link.textContent = heading.textContent
32+
link.textContent = [...heading.childNodes].reduce((acc, el) => { return acc + (el.nodeType === Node.TEXT_NODE ? el.textContent : '') }, '')
3333
links[(link.href = '#' + heading.id)] = link
3434
var listItem = document.createElement('li')
3535
listItem.dataset.level = parseInt(heading.nodeName.slice(1)) - 1

0 commit comments

Comments
 (0)