瀏覽代碼

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

Frederic G. MARAND 8 年之前
父節點
當前提交
e16af44c2e
共有 1 個文件被更改,包括 8 次插入1 次删除
  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/>');
+    }
   });
 });