简体   繁体   中英

Jquery : Toggle DIV Class name in every second

I have two DIV class : demo1 and demo2

<div class="demo1">example text</div>

so How can i change div class name with every second : demo1 to demo2 and demo2 to demo1

Use toggleClass() with setInterval()

jQuery(function () {
    var $div = $('.demo1');
    setInterval(function () {
        $div.toggleClass('demo1 demo2');
    }, 1000);
})

Demo: Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM