jquery 获取下一个名为 moreProductsBox 的 div 并使用 sliderToggle 打开它
尝试访问我单击的链接后的下一个可用 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()
};
*更新的标记更加清晰
Trying to get access to the next available div after the a link that i click, with a class of moreProductsBox and then slideToggle it open.
This is what i have now:
Link:
<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 is:
// Show Hidden Product Boxes on Expand
$(".viewMoreProducts").click(function() {
$(this).nextAll(".moreProductsBox:first").slideToggle()
};
*Updated markup to be more clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
next 适用于兄弟节点,html 中没有“下一个”div
http://api.jquery.com/ next/
描述:获取匹配元素集中每个元素的紧随其后的同级元素。如果提供了选择器,则仅当它与该选择器匹配时,它才会检索下一个同级。
发布包含锚点和 div 标记的 html,您可能需要类似的内容
next works on sibling nodes, there is no 'next' div in your html
http://api.jquery.com/next/
Description: Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.
post the html which contains both your anchor and div mark up, you probably want something like
我使用 moreProductsBox 类访问下一个 div 的唯一方法是:
给出的其他建议不起作用。
the only way for me to access that next div with the class moreProductsBox was to do:
The other suggestions that were given didn't work.
文档中的
.moreProductsBox
与.viewMoreProducts
有何关系?它是文档中其他元素的同级元素还是子元素?如果它是同级,但不是下一个,您可以尝试:因为
.next
只会为您提供下一个同级。How is
.moreProductsBox
related to.viewMoreProducts
in the document? Is it a sibling, or a child of some other element further down your document? If it is a sibling, but not the very next one, you might try:since
.next
will only get you the very next sibling.