displayCitations function manual


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. function displayCitations() {
  2. var quotes = document.getElementsByTagName("blockquote");
  3. for (var i=0; i<quotes.length; i++) {
  4. if (!quotes[i].getAttribute("cite")) continue;
  5. var url = quotes[i].getAttribute("cite");
  6. var quoteChildren = quotes[i].getElementsByTagName("*");
  7. var quoteChildren = quotes[i].getElementsByTagName('*');
  8. if (quoteChildren.length < 1) continue;
  9. var elem = quoteChildren[quoteChildren.length - 1];
  10. var link = document.createElement("a");
  11. var link_text = document.createTextNode("source");
  12. link.appendChild(link_text);
  13. link.setAttribute("href",url);
  14. var superscript = document.createElement("sup");
  15. superscript.appendChild(link);
  16. elem.appendChild(superscript);
  17. }
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.