jQuery 找到最近的父级 Div

标签 jquery jquery-selectors siblings

我正在尝试通过以下场景学习 jQuery。为此,我在阅读了多个 SO 问题后尝试了以下 jQuery;但没有成功

$(this).closest('.viewLogText').parent().find('.reportLog').css("display", "none");

场景:

具有 Css 类“repeaterRecord”的 div 中有三个子 div 元素。子 div 带有 css 类 - RepeaterIdentifier、viewLogTitle 和 reportLog。

有两个具有此结构的 div(具有 Css 类“repeaterRecord”的 div)。

enter image description here

具有viewLog类的div如下所示。

   <div class="viewLogTitle">
        <div class="viewLogText">
            View Report Log
        </div>
        <div>
            <img alt="Expand" src="Images/PlusIcon.GIF" class="expandLogIcon" />
            <img alt="Collapse" src="Images/MinusIcon.GIF" class="collapseLogIcon" />
        </div>
    </div>

当单击collapseLogIcon图像时,我需要(仅)隐藏最近的带有“reportLog”类的div(与“viewLogTitle”处于同一级别)。我们如何使用 jQuery 来做到这一点?

更新的工作示例:

http://jsfiddle.net/Lijo/L9w4F/11/http://jsfiddle.net/Lijo/L9w4F/8/http://jsfiddle.net/Lijo/L9w4F/12/

引用:

  1. Efficient, concise way to find next matching sibling?

  2. jquery select siblings 'until'

最佳答案

您可以使用.siblings()来查找最近的div

<强> API HERE

关于jQuery 找到最近的父级 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11862109/

相关文章:

javascript - 将复选框存储在本地存储中

jquery - 为什么这个带句点的 jquery 选择器不起作用

html - 相邻兄弟 : too many elements between the rules

jQuery 选择名称为数组的输入元素

javascript - 如何使用 jQuery 删除此弹出窗口中的下两个同级且仅删除下两个同级?

Jquery 返回原始值

javascript - 除非刷新页面,否则平滑滚动在 Rails 中不起作用

javascript - 如何在不使用照片编辑器的情况下实现这一目标?

javascript - Jquery ajax 发布到 MVC2 操作

javascript - 根据其他选择框的值生成选择框的值