Jquery在父类中选择类

标签 jquery

我正在尝试在链接的同一父类中选择一个类。

这是 html:

<div id="productList">
    <ul>
        <li class="productListItem">                
            Product 1 <span class="smallText">stuff</span>
            <div class="skuFinder"></div>
            <ul class="merchantsInProductList">
                <li><a class="merchantLink" href="/Pricing/SkuFinder/1/1">Merchant 1 $5.99</a></li>                    
            </ul>
        </li>            
    </ul>                
</div>

当单击“merchantLink”类时,我想对“skuFinder”类执行 jQuery 加载

选择“skuFinder”类别的最佳方式是什么?

最佳答案

$("a.merchantLink").click(function(){
   // (if div is the previous element to ul)
   $(this).closest("ul.merchantsInProductList").prev("div.skuFinder");

   // (if div is the not previous element to ul and is anywhere inside li with 
   //class productListItem)
   $(this).closest("li.productListItem").find("div.skuFinder");
});

关于Jquery在父类中选择类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2236533/

相关文章:

javascript - jquery 在来自数据库的 php cicle 中悬停时显示 div

javascript - Jquery 效果在鼠标悬停时显示 <li><a> 菜单元素的溢出文本

javascript - 检测访问者是否来自 Google 搜索的最可靠方法?

javascript - jQuery:是焦点元素吗?

javascript - 使用正则表达式出现无效量词错误(英国电话号码)

javascript - Object.将 this 与 NodeList 一起分配

javascript - 如何编写一个非阻塞的javascript方法?

javascript - 每 n 秒执行一次函数

javascript - 为什么我的 javascript/jquery 代码不能按预期用于复选框

php - 如何对两个变量求和 : constant and iterated in text input's "name"?