我正在尝试通过以下场景学习 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)。
带有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/11/ and
http://jsfiddle.net/Lijo/L9w4F/8/ http://jsfiddle.net/Lijo/L9w4F/8/ and
http://jsfiddle.net/Lijo/L9w4F/12/ http://jsfiddle.net/Lijo/L9w4F/12/
参考:
有效、简洁的方法来找到下一个匹配的兄弟姐妹? https://stackoverflow.com/questions/4933236/efficient-concise-way-to-find-next-matching-sibling
jquery 选择兄弟姐妹“直到” https://stackoverflow.com/questions/1829811/jquery-select-siblings-until
您可以使用.siblings()
找到最近的div
.
API HERE http://api.jquery.com/siblings/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)