ソースを参照

Listing 3.12: targeting this.

Frederic G. MARAND 9 年 前
コミット
c489dab013
1 ファイル変更4 行追加2 行削除
  1. 4 2
      Chapter 3/03.js

+ 4 - 2
Chapter 3/03.js

@@ -5,8 +5,10 @@ $(document).ready(function () {
     .hover(
       function () { $(this).addClass('hover'); },
       function () { $(this).removeClass('hover'); })
-    .click(function () {
-      $('#switcher button').toggleClass('hidden');
+    .click(function (event) {
+      if (event.target === this) {
+        $('#switcher button').toggleClass('hidden');
+      }
     });
 
     $('#switcher-default').addClass('selected');