How to programmatically collapse space in empty div when google ad does not show

前端 未结 4 832
攒了一身酷
攒了一身酷 2021-02-14 12:45

Is there any way to programmatically collapse the empty space that results when a google ad does not show? If so, I would love to see an illustrative example of the same.

<
4条回答
  •  逝去的感伤
    2021-02-14 13:50

    I know this is old, but since I've been dealing with this now. A simple enough way to do this in jQuery is to check for all elements with the class adsbygoogle that have no child inside.

    This selects all the elements with that class and hides them, effectively collapsing them.

    $(".adsbygoogle:empty").hide();

    You can do a lot of other stuff with it too, like if it's in a div and you need to hide that too, use the $(".adsbygoogle:empty").parent().hide() to collapse it further.

    I'm sure this can be done with vanilla javascript as easily. I suggest to run this line of code after the DOM has loaded and even wait like 10 seconds just to see if google populates the ads.

提交回复
热议问题