如果另一个类显示为none,则更改一个类的边距

Change margin of one class if another class display: none

本文关键字:一个 显示 另一个 none 如果      更新时间:2023-09-26

我需要设置一个if语句,类似于:

如果divID1元素style="display:block",则divCLASS1添加CSS style="margin-right:0px"

<script type="text/javascript">
<!--
           if ($('#w2btoTop').element.style('display') == 'block')
    $(".livehelp").css('margin-right','0px');
}
//-->
</script>

我不知道我在做什么,但很想看看我是否接近解决这个问题!

下面应该可以工作:

if ($("#w2btoTop").css("display") === "block") {
    $(".livehelp").css("margin-right", "0px");
}

我建议你事先阅读官方的jQuery文档

检查元素可见性的一种方法:

$('#w2btoTop').is(":visible") // true if visible
$('#w2btoTop:visible').length // > 0 if visible