/ Published in: JavaScript
JS function that add a link included in the cite attribute of the blackquote HTML element as sup element close to the blackquote. Takes no argument.
From book Dom Scripting by Jeremy Keith.
From book Dom Scripting by Jeremy Keith.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function displayCitations() { var quotes = document.getElementsByTagName("blockquote"); for (var i=0; i<quotes.length; i++) { if (!quotes[i].getAttribute("cite")) continue; var url = quotes[i].getAttribute("cite"); var quoteChildren = quotes[i].getElementsByTagName("*"); var quoteChildren = quotes[i].getElementsByTagName('*'); if (quoteChildren.length < 1) continue; var elem = quoteChildren[quoteChildren.length - 1]; var link = document.createElement("a"); var link_text = document.createTextNode("source"); link.appendChild(link_text); link.setAttribute("href",url); var superscript = document.createElement("sup"); superscript.appendChild(link); elem.appendChild(superscript); } }