jquery
2012-04-04 62 views 0 likes 
0

在jQuery中遍歷時遇到問題..好似一個簡單的問題..但我正在敲我的腦袋。我試過.closest().next().find() ..和縹緲jQuery遍歷.next().show()

HTML:

<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--> 

的Jquery:

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

.full_item CSS設置爲display:none 的目的是顯示在div :full_item點擊跨度.more

Thanks in adv暗瘡!

+0

'的console.log(這)'可以在看到比你期待什麼 – Jack 2012-04-04 14:16:24

回答

2

.morep之內,它在.news_text之內,而.full_item是其中的同胞。所以下面應該做的伎倆:

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

.siblings()

+0

正在抓住非常有幫助'next'對他的dom不起作用。它不會選擇一個元素 – mkoryak 2012-04-04 14:18:08

+0

感謝您的回覆,但那也不是玩球。 – 2012-04-04 14:18:49

+0

.siblings()工作得很好 - 感謝基督徒! – 2012-04-04 14:20:15

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

跨度不是.full_item的兄弟。嘗試

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

也,功能next將無法​​正常工作,因爲.full_item不會立即p的父以下。改爲使用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(); 
});​ 
相關問題