使用"if"更改CSS.在jQuery中 [英] Change CSS using "if" in jQuery

查看:60
本文介绍了使用"if"更改CSS.在jQuery中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有在孩子可见的情况下,才可以更改父div的CSS吗?然后再回来,当没有???我一直在绞尽脑汁,并且所有Googled和jQuery文档都记录在案.

Is there a way to change the CSS of a parent div only if the child is visible? And back again when not??? I've been racking my brains and I'm all Googled and jQuery documentationed out.

推荐答案

$(".childClass").each(function(){
    if($(this).is(":visible"))
    {
        $(this).parent().css("some_attribute", "some_value");
    }
    else
    {
        $(this).parent().css("some_attribute", "default_value");
    }
});

您还可以在父级上使用addClass/RemoveClass,但是如果要删除用作选择器一部分的子类来查找子元素,则要小心.

You can also use addClass/RemoveClass on the parent, but be careful if you remove a class that you're using as part of the selector to find the child element.

这篇关于使用"if"更改CSS.在jQuery中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆