2012-12-08 2 views
0

LI 내부의 링크에 클래스가 있는지 알아 내려고합니다. 어떻게해야합니까? 여기에 지금까지 무엇을하려고했는데 것 : jQuery : li 내 하이퍼 링크 클래스 가져 오기

<a class="filtergallery" id="p" href="#">Portraits</a> <a class="filtergallery" id="n" href="#">Newborn</a> <a class="filtergallery" id="pe" href="#">Pets</a> 

<ul class="portfolio-wrap"> 

<li><a class="p" href="#" title="First Pic"><img src="#" alt="First Pic" /></a></li> 
<li><a class="pe" href="#" title="Second Pic"><img src="#" alt="Second Pic" /></a></li> 
<li><a class="n" href="#" title="Third Pic"><img src="#" alt="Third Pic" /></a></li> 
<li><a class="pe" href="#" title="Fourth Pic"><img src="#" alt="Fourth Pic" /></a></li> 

jQuery를 (특정 리튬의 숨기려) :

 $('.filtergallery').click(function(event){ 

     var theid = $(this).attr('id'); 
     $('.portfolio-wrap li').each(function(){ 

      if (!hasClass(theid)) { // I need to see if the hyperlink inside the LI has this class...? 
       hide(); 
      } 

     }); 

    }) 

답변

1

당신에게 ' d는 실제로 anc를 선택할 필요가있다. hor 태그를 선택하십시오. 이 바이올린을 한번보세요. 또한 귀하가 가지고있는 코드는 클릭을 기반으로 링크를 숨김 해제하지 않습니다 (클릭시에만 숨기고 다른 링크를 클릭 할 때 다시 숨기지 않습니다 - 요구 사항 인 경우). 모든 링크를 보여주고 클릭 할 때 해당 링크를 숨긴 다음 해당 링크를 숨기는 기능을 만들 수 있습니다.

http://jsfiddle.net/UV7nS/

<a class="filtergallery" id="p" href="#">Portraits</a> <a class="filtergallery" id="n" href="#">Newborn</a> <a class="filtergallery" id="pe" href="#">Pets</a> 

<ul class="portfolio-wrap"> 

<li><a class="p" href="#" title="First Pic"><img src="#" alt="First Pic" /></a></li> 
<li><a class="pe" href="#" title="Second Pic"><img src="#" alt="Second Pic" /></a></li> 
<li><a class="n" href="#" title="Third Pic"><img src="#" alt="Third Pic" /></a></li> 
<li><a class="pe" href="#" title="Fourth Pic"><img src="#" alt="Fourth Pic" /></a></li> 

$('.filtergallery').click(function(event){ 

     var theid = $(this).attr('id'); 
     $('.portfolio-wrap li a').each(function(){ 

      if (!$(this).hasClass(theid)) { // I need to see if the hyperlink inside the LI has this class...? 
       $(this).hide(); 
      } 

     }); 

    })​ 
0
$('.filtergallery').click(function(event){ 
    $('.portfolio-wrap li:not(:has(a.'+$(this).attr('id')+'))').hide(); 
} 

http://jsfiddle.net/T6GLr/

< 3 일 : 라이너


편집 : 미안하지만, 당신은 그것을 가지고 있지 않은 사람들을 숨기고 싶었습니다. 코드를 편집했습니다.

관련 문제