diff --git a/dfn.js b/dfn.js index 71c73c8..1708622 100644 --- a/dfn.js +++ b/dfn.js @@ -60,11 +60,11 @@ function dfnShow(event) { if (node) { var panel = document.createElement('div'); panel.className = 'dfnPanel'; - if (node.id) { + if (node.id || node.parentNode.id) { var permalinkP = document.createElement('p'); var permalinkA = document.createElement('a'); - permalinkA.href = '#' + node.id; - permalinkA.textContent = '#' + node.id; + permalinkA.href = '#' + (node.id || node.parentNode.id); + permalinkA.textContent = '#' + (node.id || node.parentNode.id); permalinkP.appendChild(permalinkA); panel.appendChild(permalinkP); } @@ -86,6 +86,10 @@ function dfnShow(event) { for (var i = 0; i < sourceLinks.length; i += 1) { var link = sourceLinks[i]; var header = dfnGetCaption(link); + // The caption could be null for a link in the toc. It happens + // when, say, the id is "the-id-attribute". Ignore it of course. + if (!header) + continue; var a = document.createElement('a'); if (!link.id) link.id = 'dfnReturnLink-' + dfnUniqueId++;