views:

44

answers:

3

How to hide adsense iframe/div when no ads for this box are available?

A: 

Get the name/ID of the iframe and just use .hide()

If you can't find a suitable selector, wrap the ad in a div with an id e.g.

<div id='some_google_ad'>
 // Google add code goes in here
</div>

and in your javacsript

$("#some_google_ad").hide();

Note there is no way of telling if your ad or ads are showing a community service announcement or a paid advertisement.

And I would suspect that having an adsense ad container on a page and having it hidden would be against the adsense TOS.

xiaohouzi79
A: 

If its thoroughly empty then the folloing should do the trick : $("div:empty").hide();

This code is untested, as I do not know the structure of ad sense. But let me know how it goes.

This makes use of the empty selector that is available in jQuery.

Description: Select all elements that have no children (including text nodes).

Russell Dias