Jquery在选定元素旁边展开div

时间:2013-04-30 10:11:20

标签: jquery html5

我的Html看起来像

<h3><a href="#" title="story title">Story Title</a>
    <img class="expandstory" src="/images/plus.png" /></h3>
<div class="description">Short description about the story</div>

我需要jquery,当用户点击expandstory图片时会扩展描述。

我用过`

$(".expandstory").click(function()  {
     $(".description").slideUp(500);
     $(this).nextAll('.description:first').slideToggle(500);
}`

但没用。请给我一个解决方案。提前谢谢。

2 个答案:

答案 0 :(得分:3)

试试这个:

$(".expandstory").click(function()  {
     $(".divisionWrap div ul").slideUp(500);
     $(this).parent().nextAll('.description:first').slideToggle(500);
});

另外,作为建议,您不需要使用nextAll()查看逻辑。

你可以这样做:

$(this).parent().next('.description').slideToggle(500);

答案 1 :(得分:1)

尝试

$(".expandstory").click(function()  {
     var el = $(this).closest('h3').next('.description');
     $(".description").not(el).slideUp(500);
     el.slideToggle(500);
}