views:

40

answers:

2

Hi All,

I have 3 div's drawing content from fields in a database:

<div id="one">{data_one}</div>
<div id="two">{data_two}</div>
<div id="three">{data_three}</div>

If none of these three div's have data, can I add some jQuery to hide another div?

Thanks, Jack

+1  A: 
if($('#one').html() == '' && $('#two').html() == '' && $('#three').html() == '') {
    $('#anotherDiv').hide();
}
David Hedlund
+2  A: 

I have a strong feeling that this would be better handled on the server side, since you would probably like this to work for people who have JavaScript disabled as well.

If it needs to be in jQuery though, you could do something like this:

$(function() {
   if($("#one").html() == "" && $("#two").html() == "" && $("#three").html() == "") {
      $("#someOtherDiv").hide();
   }
}
Franz
Hi Franz. Thank you so much for your help! I am starting to get the hang of this jQuery thing.... We are using Adobe Business Catalyst CMS for some of our clients and unfortunately (being a hosted solution) we can not do anything server side. We have built some functionality using their web app builder and need to fill the gaps with jQuery.
Jackson