G
G
gl_evhen2015-09-22 12:14:50
JavaScript
gl_evhen, 2015-09-22 12:14:50

Cycling element class?

Hello, please tell me a script or keywords to search for it, which could change the element's class from one to the second, after a certain period of time.
For example the element

<div class="first-class"> 
через минуту становиться
<div class="second-class"> ,
а ещё через минуту опять
<div class="first-class">

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-09-22
@gl_evhen

var arrD = ["first", "second", "yet"], i = -1; 
//Классы - .first, .second, .yet соотв.
setInterval(function(){
  document.querySelector("div").className = arrD[
    i = ++i%arrD.length
  ];
}, 60000);

Sample: jsfiddle.net/pofw0vLw/1

I
Ivan Palamarchuk, 2015-09-22
@delef

setInterval(function() {
if ($('div').hasClass('first-class')) {
$(this).removeClass('first-class').addClass('second-class');
} else if ($('div').hasClass('second-class')) {
$(this).removeClass('second-class').addClass('first-class');
}
}, 5000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question