Browse Source

Exercise 4: toggle bold on author, using a selector context.

Frederic G. MARAND 8 years ago
parent
commit
e16af44c2e
1 changed files with 8 additions and 1 deletions
  1. 8 1
      Chapter 5/05.js

+ 8 - 1
Chapter 5/05.js

@@ -63,6 +63,13 @@ $(document).ready(function () {
   });
 
   $('#f-author').click(function () {
-    $(this).wrapInner('<b/>');
+    var $this = $(this);
+    var $b = $('b', this);
+    if ($b.length) {
+      $this.text($b.text());
+    }
+    else {
+      $this.wrapInner('<b/>');
+    }
   });
 });