jQuery查找最接近的父级Div [英] jQuery to find nearest Div of Parent
问题描述
我正在尝试在以下情况下学习jQuery.为此,我在阅读了多个SO问题后尝试了以下jQuery;但这没用
I am trying to learn jQuery with the following scenario. For this, I tried the following jQuery after reading multiple SO questions; but it did not work
$(this).closest('.viewLogText').parent().find('.reportLog').css("display", "none");
场景:
一个div中有三个子div元素,这些元素具有Css类"repeaterRecord".子div具有CSS类-RepeaterIdentifier,viewLogTitle和reportLog.
There are three child div elements in a div that has Css class "repeaterRecord". The child divs are with css classes - repeaterIdentifier, viewLogTitle and reportLog.
有两个具有这种结构的div(div具有Css类"repeaterRecord").
There are two divs with this structure (div that has Css class "repeaterRecord").
具有viewLog类的div如下所示.
The div with viewLog class is as shown below.
<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做到这一点?
When the collapseLogIcon image is clicked, I need to hide (only) the nearest div with "reportLog" class (at the same level of "viewLogTitle"). How can we do it using jQuery?
更新的工作示例:
http://jsfiddle.net/Lijo/L9w4F/11/和 http://jsfiddle.net/Lijo/L9w4F/8/和 http://jsfiddle.net/Lijo/L9w4F/12/
参考:
推荐答案
您可以使用siblings()
方法:
$(this).closest('.viewLogText').siblings('.reportLog').hide()
您还可以尝试与.css("display", "none");
这篇关于jQuery查找最接近的父级Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!