What is the different between these 2 snippets?

What is the different between these 2 snippets?

Need somebody to help me these 2 snippets for code produce different results. Particularly the highlighted part. 

  1. $(function () {
  2. //Code Snippet 1
  3.     $('div.chapter a').attr({
  4.         'rel':'external',
  5.         'title': 'Learn more about '+ $(this).text() + ' at Wikipedia'
  6.     })
  7. //Code snippet 2
  8.     $('div.chapter a').each(function (index){ $(this).attr({
  9.         'rel': 'external',
  10.         'title': 'Learn more about ' + $(this).text() + ' at Wikipedia'
  11.     }) })
  12. })

I am running the above code snippets individually on the following HTML individually. 
  1. <!DOCTYPE html>

  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>A Christmas Carol</title>
  6.     <link rel="stylesheet" href="04.css" type="text/css" />
  7.     <script src="./scripts/jquery.js"></script>
  8.     <script src="./scripts/05Dom.js"></script>
  9.   </head>
  10.   <body>
  11.       <h1 id="f-title">Flatland: A Romance of Many Dimensions</h1>
  12.       <div id="f-author">by Edwin A. Abbott</div>
  13.       <h2>Part 1, Section 3</h2>
  14.       <h3 id="f-subtitle">Concerning the Inhabitants of Flatland</h3>
  15.       <div id="excerpt">an excerpt</div>
  16.       <div class="chapter">
  17.           <p class="square">
  18.               Our Professional Men and Gentlemen are Squares
  19.               (to which class I myself belong) and Five-Sided Figures or <a>href="http://en.wikipedia.org/wiki/Pentagon">Pentagons</a>.
  20.           </p>
  21.           <p class="nobility hexagon">
  22.               Next above these.....
  23.               ..<a href="http://en.wikipedia.org/wiki/Hexagon">Hexagons</a>,
  24.               ae r.... <a href="http://en.wikipedia.org/wiki/Polygon">Polygonal</a>....hed from a <a href="http://en.wikipedia.org/wiki/Circle">circle</a>, 
  25.               he is
  26.               ..
  27.           </p>
  28.           <p>
  29.               <span class="pull-quote">
  30.                   It is a <span class="drop">
  31.                       Law of
  32.                       Nature
  33.                   </span> with ... <strong>....</strong> than ..
  34.               </span>, so ....
  35.           </p>
  36.           <!-- . . . code continues . . . -->
  37.       </div>
  38.   </body>
  39. </html>

The output when i run the 1st code snippet as viewed by placing the mouse pointer over the 'hexagon' link

The output when i run the 2nd code snippet as viewed by placing the mouse pointer over the 'hexagon' link


I wanted to understand why does $(this).text() generates a different output in each of these cases. In 1st case it seem to be referring to the entire html and in the 2nd case it refers to the text in the <a> tag which was the actual intention. The rel attribute turns out fine in both the cases.