/* * * ATTRIBUTE MANIPULATION * */ // Use .attr() to add "inhabitants" class to all paragraphs. $(document).ready(function() { $('p').each(function(index) { var currentClass = $(this).attr('class'); $(this).attr('class', currentClass + ' inhabitants'); }); }); // Use attr() to add an id, rel, and title. $(document).ready(function() { $('div.chapter a[href*=wikipedia]').each(function(index) { var $thisLink = $(this); $(this).attr({ 'rel': 'external', 'id': 'wikilink-' + index, 'title': 'learn more about ' + $thisLink.text() + ' at Wikipedia' }); }); }); /* * * BACK-TO-TOP LINKS * */ $(document).ready(function() { $('').prependTo('body'); $('back to top').insertAfter('div.chapter p:gt(2)'); }); /* * * FOOTNOTES * */ $(document).ready(function() { $('
    ').insertAfter('div.chapter'); $('span.footnote').each(function(index) { $(this) .before( ['', '' + (index+1) + '', '' ].join('') ) .appendTo('#notes') .append( ' (context)' ) .wrap('
  1. '); }); }); /* * * PULL QUOTES * */ $(document).ready(function() { $('span.pull-quote').each(function(index) { var $parentParagraph = $(this).parent('p'); $parentParagraph.css('position', 'relative'); var $clonedCopy = $(this).clone(); $clonedCopy .addClass('pulled') .find('span.drop') .html('…') .end() .prependTo($parentParagraph) .wrap('
    '); var clonedText = $clonedCopy.text(); $clonedCopy.html(clonedText); }); });