0

尝试在我单击的链接之后访问下一个可用的 div,其中包含一个 moreProductsBox 类,然后通过滑动切换它打开。

这就是我现在拥有的:

关联:

<div class="productContent">
<p><a href="#" onclick="return false;"  class="viewMoreProducts">View Related Products </a></p>
</div>
<div class="productSelectBar">
<div class="selectBar">
</div>
</div>

<!-- View More Products Box -->
<div class="moreProductsBox" style="display:none;">
</div>

jQuery是:

// Show Hidden Product Boxes on Expand  
$(".viewMoreProducts").click(function() {
    $(this).nextAll(".moreProductsBox:first").slideToggle()
};

*更新的标记更清晰

4

3 回答 3

1

在文档中是如何.moreProductsBox关联.viewMoreProducts的?它是文档中的兄弟元素还是其他元素的子元素?如果它是兄弟姐妹,但不是一个,您可以尝试:

$(this).nextAll(".moreProductsBox:first").slideToggle();

因为.next只会让你成为下一个兄弟姐妹

于 2010-12-29T22:55:02.040 回答
0

next 适用于兄弟节点,您的 html 中没有“下一个”div

http://api.jquery.com/next/

描述:获取匹配元素集中每个元素的紧随其后的兄弟。如果提供了选择器,则仅当它与该选择器匹配时,它才会检索下一个兄弟。

发布包含锚点和 div 标记的 html,你可能想要类似的东西

// this should work if the p tag has a sibling div moreProductsBox
$(this).parent().next('moreProductsBox').slideToggle;
于 2010-12-29T22:57:04.710 回答
0

我使用 moreProductsBox 类访问下一个 div 的唯一方法是:

$(this).parent().parent().parent().find(".moreProductsBox:first").slideToggle();

给出的其他建议无效。

于 2010-12-30T18:32:01.830 回答