开发者

switich two div's with jquery on the base of condition

开发者 https://www.devze.com 2023-02-14 02:43 出处:网络
hello I have two div on my page. <div id=\"adsense\" style=\"display:block\">some stuff</div>

hello I have two div on my page.

<div id="adsense" style="display:block">some stuff</div>
<div id="timeout" style="display:none>Some stuff</div>

I have a variable var type.

The page on which these two div's are loads two times. First time the ty开发者_C百科pe=0. At this time i want to show the <div id="adsense">. Then the page goes to other pages and when the page loads second time the type becomes 1.

Now what I want is at first page load the <div id="adsense"> to be shown. When page reloads type becomes 1 I want to show the <div id="timeout"> for 9 seconds and then again switch to first div.

I want to know how can I do that? How can I embed if condition in it.


I hope I understood correctly:

(function(){
    // put the code that will evaluate the value of 'type' here

    var $adsense = $("#adsense");
    var $timeout = $("#timeout");
    if(type == 0) {
        $timeout.hide();
        $adsense.show();        
    } else if (type == 1) {     
        $adsense.hide();
        $timeout.show();        
        setTimeout(function() {
            $timeout.hide();
            $adsense.show();
        }, 9000);
    }
});

This can of course be optimized, its mainly for understanding how it works.


I'm not sure I fully understand you but maybe you could so something like

function showAdsenseDiv(){
    //show adsense div    
}

function showTimeoutDiv(){
    //show timeout div
}

showAdsenseDiv();
setTimeout(showTimeoutDiv, 9000);
0

精彩评论

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

关注公众号