2012-01-20 14 views
0
私の見解では

htmlリストのグループからリストを非表示にするにはどうしたらよいですか?

<ul> 
<li id="list"> 
<table cellpadding="0" cellspacing="0" width="100%" class="grid-table08" id="table1"> 
<tbody> 
<tr><td><img src="../../Content/Images/downarrow.gif" title="Hide Details" class="hide"> 
</td></tr> 

<tr><td align="left" valign="top" width="15" nowrap="nowrap"> 
Hii good morning 
</td> 
<tr> 
</table> 
</li> 

<li> 
<table cellpadding="0" cellspacing="0" width="100%" class="grid-table08" id="table1"> 
<tbody> 
<tr><td><img src="../../Content/Images/downarrow.gif" title="Hide Details" class="hide"> 
</td></tr> 

<tr><td align="left" valign="top" width="15" nowrap="nowrap"> 
Hii good evening 
</td> 
<tr> 
</table> 
</li> 

</ul> 

<script type="text/javascript"> 
$(function() { 

    $(".hide").live("click", function() { 

     $(".hide").closest("li").hide("slow"); 


    }); 

}); 

を次のように私は

私は特定の李を非表示にする必要があるIDの皮と私のスクリプトを画像をクリックすると、合計10 Liがあります。

しかし、その誰も働いていないpls私を助ける

+0

は、なぜあなたは '#のli'を使用しない代わりに、 '.closest( 'li')'で選択するだけですか?また、HTMLのIDとして、またJavaScriptのクラス( '.'を参照)として' hide'を使用しています。 – m90

+0

HTMLタグIDは一意でなければならず、ID = "リスト"を複数回使用しています。それを修正し、それが役立つかどうかを確認してみてください – Sparky

+0

ああ申し訳ありません@ Sparky、@ m90 .. –

答えて

1

あなたのHTMLにクラス=「非表示」に複数の要素..change idは=「非表示」に一意のIDを使用するカント「= ID =「非表示」の代わりにクラスを持っています隠す"。

WRONG: <img src="../../Content/Images/downarrow.gif" title="Hide Details" id="hide"> 
GOOD: <img src="../../Content/Images/downarrow.gif" title="Hide Details" class="hide"> 

$(".hide") - this one selects all elements with class="hide" 

UPDATE:あなたは、クラスを使用する必要が<li id="list">

はまた、あなたが同じID = "リスト" で複数のLIタグを持っている<li class="list">

IDの違いをクラスは1つの要素を識別するためにIDを使用できるのに対して、クラスは複数の要素を識別するために使用できるということです。

SOLUTION:

<li class="list"> 
<table cellpadding="0" cellspacing="0" width="100%" class="grid-table08" id="table1"> 
<tbody> 
<tr><td><img src="../../Content/Images/downarrow.gif" title="Hide Details" class="hide"> 
</td></tr> 

<tr><td align="left" valign="top" width="15" nowrap="nowrap"> 
Hii good morning 
</td> 
<tr> 
</table> 
</li> 

<li class="list"> 
<table cellpadding="0" cellspacing="0" width="100%" class="grid-table08" id="table1"> 
<tbody> 
<tr><td><img src="../../Content/Images/downarrow.gif" title="Hide Details" class="hide"> 
</td></tr> 

<tr><td align="left" valign="top" width="15" nowrap="nowrap"> 
Hii good evening 
</td> 
<tr> 
</table> 
</li> 

</ul> 

$(function() { 
    $(".hide").live("click", function() { 
     $(this).parents("li.list:first").hide("slow"); 
    }); 
}); 

ここでデモを試してみてください。(それはIDたかのように)http://jsfiddle.net/RtXn9/

+0

感謝を隠したまで –

+0

を補正するための – papaiatis

+0

のために動作しますが李に、私はすでに使用されている場合、私の解決策をしてください受け入れる@papaiatis –

1

あなたはあなたのimgタグが

$(document).ready(function(){  

     $(".hide").live("click", function() {  
      $(this).parents().find('li').hide('slow'); 

     });  

    }); 
+0

ありがとうが、全体のliを非表示にする –

+0

画像だけを隠したいので? – coolguy

+0

は..私は、すべてのLiが、それはあなた – coolguy