Set a timeout before show a div

254 Views Asked by At

I have a problem, I want to show a div after 5 seconds, I tried :

if(obj.google_analytics.is_casino_game){
  setTimeout(function() { }, 500);
}
document.getElementById('addsense-pub').setAttribute('class','display-block');

But does not work. Can you help me please?

3

There are 3 best solutions below

0
On

Not sure I get it, but you have to at least put the code you want executed inside the timeout

if(obj.google_analytics.is_casino_game){
    setTimeout(function() {
        document.getElementById('addsense-pub').setAttribute('class','display-block');
    }, 5000);
}

Note that hiding and showing ads from adSense in this way is generally considered breaking the TOS

0
On

You can use delay:

if (obj.google_analytics.is_casino_game) {
    $('#addsense-pub').delay(5000).show();
    // Will add delay of 5 seconds before showing the element
}

Docs: https://api.jquery.com/delay/

OR

Using setTimeout:

if (obj.google_analytics.is_casino_game) {
    setTimeout(function () {
        $('#addsense-pub').show();
    }, 5000);
}
0
On

Write the code inside setTimeout function()

 setTimeout(function() { 
   $('#addsense-pub').show();

}, 5000);