开发者

Hide a div when another is empty

开发者 https://www.devze.com 2022-12-13 01:16 出处:网络
its my fisrt question, cause i dont find a answer in the search... Its possible to hide a div, when another is empty? Here is the case:

its my fisrt question, cause i dont find a answer in the search...

Its possible to hide a div, when another is empty? Here is the case:

<div id='TwitterTrackbacksWrapper'>
<h开发者_开发百科4><img align='bottom' alt='Twitter Trackbacks' src='http://Imagens/twitter-bird.png'/> twitter trackbacks</h4>
<div class='twitter-trackbacks' id='twitter-trackbacks'/>
</div>

I want to hide/remove the whole Div ID TwitterTrackbacksWrapper when there is nothing to show on a div/class twitter-trackbacks. That is possible?


On your onload of the page, check the twitter-trackbacks div's innerHtml property. If empty. set the style property of the TwitterTrackbacksWrapper to display:'none'.

Something like:

function hideIfEmpty()
{
  var inner = document.getElementById("twitter-trackbacks");
  if (inner.innerHTML=="")
    document.getElementById("TwitterTrackbacksWrapper").style="display:none;";
}


Sure, when you populate the data for the "twitter-trackbacks" area, if its empty, set the style of the TwitterTrackbacksWrapper to display: none.


This solution works using JQuery.

if ($('#TwitterTrackbacksWrapper').html().length == 0) {
    //Then, there is nothing in the div 
    //Please remove me.
}

Let me know if it helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号