Jquery如果我的div是空的

use*_*625 0 css jquery if-statement

我在这里有这个脚本

<script type="text/javascript">
$(document).ready(function () {
    if($('.subhead').is(':empty')){
        $(this).css('background-color', 'none !important');
    }

});
</script>
Run Code Online (Sandbox Code Playgroud)

我想在这里做的是说如果我的类.subhead是空的然后改变了背景颜色,我在代码中有多个.subhead div,如果我运行这样的脚本

<script type="text/javascript">
    $(document).ready(function () {
        if($('.subhead').is(':empty')){
            alert('hi');
        }else{
            alert('hello');
        }
    });
    </script>
Run Code Online (Sandbox Code Playgroud)

它会返回Hello

我正在尝试做什么?

Ror*_*san 5

默认设置background-colourtransparent,而不是none.试试这个:

if ($('.subhead').is(':empty')){
    $(this).css('background-color', 'transparent !important');
}
Run Code Online (Sandbox Code Playgroud)