jquery
2012-04-04 130 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(); 
});​ 
相关问题