소스 검색

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/>');
+    }
   });
 });