开发者

jQuery - If none of 3 id's have content hide this

开发者 https://www.devze.com 2022-12-13 21:11 出处:网络
I have 3 div\'s drawing content from fields in a database: <div id=\"one\">{data_one}</div>

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

<div id="one">{data_one}</div>
<div id="two">{data_t开发者_运维问答wo}</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


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();
   }
}


if($('#one').html() == '' && $('#two').html() == '' && $('#three').html() == '') {
    $('#anotherDiv').hide();
}
0

精彩评论

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