05.js 820 B

123456789101112131415161718192021222324252627
  1. $(document).ready(function () {
  2. 'use strict';
  3. // Use attr() to add an id, rel, and title.
  4. $('div.chapter a[href*="wikipedia"]').attr({
  5. rel: 'external',
  6. title: function () {
  7. return 'Learn more about ' + $(this).text() + ' at Wikipedia.';
  8. },
  9. id: function (index, oldValue) {
  10. return 'wikilink-' + index;
  11. }
  12. });
  13. // Add "back to top" links.
  14. $('<a href="#top">back to top</a>').insertAfter('div.chapter p');
  15. $('<a id="top"></a>').prependTo('body');
  16. // insertBefore <elem> prependTo <children /> appendTo </elem> insertAfter
  17. // Create footnotes.
  18. // This works just as well, in spite of what the book says.
  19. // $('span.footnote').insertAfter('div.chapter');
  20. $('span.footnote')
  21. .insertBefore('#footer')
  22. .wrapAll('<ol id="notes"></ol>')
  23. .wrap('<li></li>');
  24. });