jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery找到最近的父母Div大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用以下方案学习jQuery.为此,我在阅读了多个SO问题后尝试了以下jQuery;但它不起作用

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

场景:

div中有三个子div元素,它们具有Css类“repeaterRecord”.子div具有css类 – repeaterIdentifier,viewLogtitle和reportLog.

有两个这种结构的div(div有Css类“repeaterRecord”).

带有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/

> Efficient,concise way to find next matching sibling?
> jquery select siblings ‘until’

解决方法

你可以使用siblings()方法

$(this).closest('.viewLogText').siblings('.reportLog').hide()

你也可以尝试hide()方法,它与.css(“display”,“none”)相同;

大佬总结

以上是大佬教程为你收集整理的jQuery找到最近的父母Div全部内容,希望文章能够帮你解决jQuery找到最近的父母Div所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。