With jQuery I am trying to determine whether or not <div> has content in it or, if it does then I want do nothing, but if doesn't then I wa开发者_StackOverflow社区nt to add display:none to it or .hide(). Below is what I have come up with,
if ($('#left-content:contains("")').length <= 0) {
            $("#left-content").css({'display':'none'});
        }
This does not work at all, if the div has not content then it just shows up anyway, can any offer any advice?
Just use the :empty filter in your selectors.
$('#left-content:empty').hide();
if( $( "#left-content" ).html().length == 0 ) {
    $( "#left-content" ).hide();
}
try to remove first whitespaces:
  // first remove whitespaces
  // html objects content version:
  var content = $.trim($("#left-content).html()).length;
  if(content == 0) {
     $("#left-content).hide();
  }
  // html RAW content version:
  var content = $.trim($("#left-content).html()); // <-- same but without length
  if(content == "") {                             // <-- this == ""
     $("#left-content).hide();
  }
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论