Explorar el Código

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

Frederic G. MARAND hace 8 años
padre
commit
e16af44c2e
Se han modificado 1 ficheros con 8 adiciones y 1 borrados
  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/>');
+    }
   });
 });