2012-04-04 23 views
0

jQueryでのトラバースに問題があります。うまくいけば簡単です。しかし、私は頭を叩いています。 jQueryのjQueryトラバース.next().show()

<div class='news_box'> 
    <img src='".NEWS.$n[image]."' alt='$n[title] Image' class='news_img' /> 
    <div class='news_text'> 
     <h3>$n[title] // ".date("d.m.Y", strtotime($n[created_on]))." // ".date("H.i", strtotime($n[created_on]))."</h3> 
     <p>".substr(strip_tags($n[description]), 0, 90)."... <span title='Read More On $n[title]' class='more'>Read More</span></p> 
    </div> 
    <p class='clear'></p> 
    <div class='full_item'> 
     $n[description] 
    </div> 
</div><!--close news_box--> 

.full_itemため

$(".news_box span.more").click(function(){ 
    $(this).next(".full_item").show(); 
}); 

CSSがdisplay:none に設定されている目的は、div要素を表示することです私は.find().next().closest()を試してみました...そして灘

HTMLました:スパンのクリック時のfull_item .more

ありがとうance!

+0

'はconsole.log(この)'あなたが – Jack

答えて

2

.moreは、.news_textの内側にあるpの内部にあり、.full_itemはその兄弟です。だから、トリックを行う必要があり、次の

$(this).closest('.news_text').siblings('.full_item').show(); 

.siblings()

+0

を期待しているものと比較しつかまされているものを見ることに非常に役立ちます'next'は彼のdomのためには動作しません。それは要素を選択しません – mkoryak

+0

返事をありがとう、それはどちらかボールを再生していません。 –

+0

.siblings()さんが治療を受けました - ありがとうございましたChristian! –

-1
$(this).parent().next(".full_item").show(); 
0

スパンは.full_itemの兄弟ではありません。 .full_itemがpの親直後ではないので

$(this).parent().nextAll(".full_item").show(); 

を試みるも、機能nextは、に動作しません。代わりにnextAllを使用してください。

-1
$(".news_box span.more").click(function(){ 
    $(this).closest(".news_box").next(".full_item").show(); 
}); 

0

私はjsfiddleにソリューションを入れている:

http://jsfiddle.net/55mUj/

$(".news_box span.more").click(function(){ 
    $(this).closest('.news_text').siblings('.full_item').show(); 
});​