Posted By

alberomo on 08/19/11


Tagged

javascript manual


Versions (?)

displayCitations function manual


 / 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.

  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  

You need to login to post a comment.