Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当内容未显示时,如何隐藏div_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 当内容未显示时,如何隐藏div

Javascript 当内容未显示时,如何隐藏div,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我不熟悉HTML和CSS。现在,我有了一个包含以下代码的页面: 显示内容: <div id="row-3" ><!-- Row 3 start here --> <div class="groupz_column1" style="margin-right:0px;"><a href="http://www.xyz.in/ads/test.jpg" title=""><h2>null</h2><img alig

我不熟悉HTML和CSS。现在,我有了一个包含以下代码的页面:
显示内容

<div id="row-3" ><!-- Row 3 start here -->

   <div class="groupz_column1" style="margin-right:0px;"><a href="http://www.xyz.in/ads/test.jpg" title=""><h2>null</h2><img align="left" width="100px" height="70px" src="http://www.xyz.in/ads/test.jpg?id=225"><p>Sign off for limited time offer<p></a></div>
   <div class="groupz_column1" style="margin-right:0px;"><a href="http://www.xyz.in/ads/test.jpg" title=""><h2>Test</h2><img align="left" width="100px" height="70px" src="http://www.xyz.in/ads/test.jpg?id=194"><p>A wonderful opportunity <p></a></div>
   <div class="groupz_column1" ></div>
   <div class="groupz_column1" ></div>
   <div class="clear clearfix"></div>
</div>  

上述代码显示了两个内容。
不显示内容:

<div id="row-3" ><!-- Row 3 start here -->
   <div class="groupz_column1" ></div>
   <div class="groupz_column1" ></div>
   <div class="groupz_column1" ></div>
   <div class="groupz_column1" ></div>
   <div class="clear clearfix"></div>
</div>  

现在,我的问题是,如果内容不存在,我想隐藏。我不想在连一个内容都没有的情况下显示
。我该怎么做

编辑 我这样做了,还是不工作

   <div id="row-3" style="div:empty { display: none }">

考虑到注释,添加
空白:nowrap添加到类的css
groupz_column1
…它将删除空的
div



此外,请检查此链接,它与您的问题类似:

考虑到评论,添加
空白:nowrap添加到类的css
groupz_column1
…它将删除空的
div


此外,请检查此链接,它与您的问题类似:

DoCSS:

 #row-3{
        display: none;
    }
做css:

 #row-3{
        display: none;
    }
添加此javascript

$(document).ready(function () {
   var doHide = true;
   $("#row-3 div").each(function () {
      if ($(this).html() != '') {
          doHide = false;
      }
   });

   if ( doHide ) {
      $("#row-3").hide();
   }
});
添加此javascript

$(document).ready(function () {
   var doHide = true;
   $("#row-3 div").each(function () {
      if ($(this).html() != '') {
          doHide = false;
      }
   });

   if ( doHide ) {
      $("#row-3").hide();
   }
});
试试这个:

$('div[id^=row-]').each(function () {
    var content = false;
    $(this).find('div').each(function () {
        if (this.innerHTML != '') {
            content = true
        };
    });
    if (!content) {
        this.style.display = 'none';
    }
});
试试这个:

$('div[id^=row-]').each(function () {
    var content = false;
    $(this).find('div').each(function () {
        if (this.innerHTML != '') {
            content = true
        };
    });
    if (!content) {
        this.style.display = 'none';
    }
});

您需要检查内容长度,如果它大于零,则显示它,否则根据您的情况删除或隐藏它

 var getLength = $("#row_new .groupz_column1").html().trim().length;

    if (getLength == 0) {
        // $("#row_new").remove(); // for remove
        $("#row_new").hide(); // for hide
    }

您需要检查内容长度,如果它大于零,则显示它,否则根据您的情况删除或隐藏它

 var getLength = $("#row_new .groupz_column1").html().trim().length;

    if (getLength == 0) {
        // $("#row_new").remove(); // for remove
        $("#row_new").hide(); // for hide
    }

您是否尝试过
显示class='none'
?如果没有内容,它将不会在您的页面上显示任何内容…那么为什么要首先隐藏它???您是否在div中动态添加元素?或者,您是如何生成行的?如果没有内容,为什么要生成它?@Aishvarya
style=“display:none”
没有隐藏div您是否尝试过
display='none'
?如果没有内容,它将不会在您的页面上显示任何内容……那么为什么要首先隐藏它???您是否在div中动态添加元素?或者,您是如何生成行的?如果没有,为什么要生成它?@Aishvarya
style=“display:none”
没有隐藏分区检查
!参考链接中提到的文档类型
,这可能会有所帮助!检查
!参考链接中提到的文档类型
,这可能会有所帮助!