1

I have checked these:

I need a javascript or jQuery script to hide div which contain adsense ads. I have searched more in google and tested all the script is working fine for image and text but not working for adsense ads.

What I have noticed is that when I write a code like this :

<div id="stackoverflow">
adsense code
</div>

It automatic converted into :

<div id="stackoverflow">
<div id="adunit> <!-- adunit id for text ads --> <!-- google_image_div id for image ads --> <!-- some time it create diff id also for div -->
some code
</div> 
<iframe>
some code
</iframe>
</div>

Can anyone help me with code?

Community
  • 1
  • 1

1 Answers1

1

Using .hide on your element should work,

$('#stackoverflow').hide();

you can then show it again using

$('#stackoverflow').show();

Here's a quick fiddle to show how to hide onclick here

EDIT: It looks like you're not ending the html attribute correctly and that may be causing problems.

<div id="stackoverflow">
<div id="adunit"> <!-- <--- Here --> <!-- adunit id for text ads --> <!-- google_image_div id for image ads --> <!-- some time it create diff id also for div -->
some code
</div> 
<iframe>
some code
</iframe>
</div>
MorganF
  • 73
  • 6
  • 2
    Hello, your script working fine with image and test but not with adsense ads. `` The above script works fine for X sec, can anyone make it for hide after click. Check this : https://jsfiddle.net/suawvcm2/4/ your script is not working with adsense code – Rajeev Ranjan Sharma Mar 27 '15 at 05:05
  • Ill take another look – MorganF Mar 27 '15 at 05:31
  • 4
    Can you make after click and hide on x sec or replace div on x sec . – Rajeev Ranjan Sharma Mar 27 '15 at 06:01
  • What are you using to trigger the hide event, is it the ad its self or another button? You can move the content out of the element and then replace it later, this fiddle might work with your code: https://jsfiddle.net/suawvcm2/5/ I also couldn't get the adsense code to load correctly so i will have to assume the above code will work. – MorganF Mar 27 '15 at 06:49