Browse Source

Listing 5.5: using $(this) in a value callback.

Frederic G. MARAND 9 years ago
parent
commit
9b8b8c3f4d
1 changed files with 4 additions and 2 deletions
  1. 4 2
      Chapter 5/05.js

+ 4 - 2
Chapter 5/05.js

@@ -1,10 +1,12 @@
-
 $(document).ready(function () {
   'use strict';
 
+// Use attr() to add an id, rel, and title.
   $('div.chapter a[href*="wikipedia"]').attr({
     rel: 'external',
-    title: 'Learn more at Wikipedia',
+    title: function () {
+      return 'Learn more about ' + $(this).text() + ' at Wikipedia.';
+    },
     id: function (index, oldValue) {
       return 'wikilink-' + index;
     }