2017-10-16 5 views
0

チェックボックスをオンにした場合、.panelを非表示にしたいと思います。しかし、それは隠れていません。特定のクラスで最も近い要素を非表示にするにはどうすればよいですか?

$(".done").on("change", function() { 
 
    if ($(this).is(":checked")) { 
 
    $(this).closest(".panel").hide; 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<li class="panel" style="background:#f4f4f4;"> 
 
    <table style="width:100%"> 
 
     <tbody> 
 
      <tr> 
 
       <td style="width:45px"> 
 
        <span class="handle ui-sortable-handle"> 
 

 
        </span> 
 
        <input class="done" type="checkbox"> 
 
       </td> 
 

 

 
       <td> 
 
        <span style="min-width:100px;min-height:20px;margin-left:0px">Please hide this on check</span> 
 

 
       </td> 
 

 
      </tr> 
 
     </tbody> 
 
    </table> 
 

 
</li>

+1

'.hide'には'() 'がありません。タイプミスとしてクローズする投票 –

答えて

3

をあなたがタイプミスをした:機能hide()を呼び出す代わりに.hide

$(".done").on("change", function() { 
 
    if ($(this).is(":checked")) { 
 
    $(this).closest(".panel").hide(); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<li class="panel" style="background:#f4f4f4;"> 
 
    <table style="width:100%"> 
 
     <tbody> 
 
      <tr> 
 
       <td style="width:45px"> 
 
        <span class="handle ui-sortable-handle"> 
 

 
        </span> 
 
        <input class="done" type="checkbox"> 
 
       </td> 
 

 

 
       <td> 
 
        <span style="min-width:100px;min-height:20px;margin-left:0px">Please hide this on check</span> 
 

 
       </td> 
 

 
      </tr> 
 
     </tbody> 
 
    </table> 
 

 
</li>

+0

ああ!私は非常に集中していたので、私はちょうどこれを見過ごした「最も近い」ものが間違っていた... – Jarla

+0

今、うまくいけば、私の答えを受け入れることができますか? –

0

は愚かな私を呼び出していますが、忘れてしまいました**()**括弧jajajjaを隠す、ここにはdemo

$(".done").on("change", function() { 
console.log($(this), $(this).closest(".panel")); 
    if ($(this).is(":checked")) { 
    $(this).closest(".panel").hide(); 
    } 
}); 
関連する問題