Answer the question
In order to leave comments, you need to log in
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
var arrD = ["first", "second", "yet"], i = -1;
//Классы - .first, .second, .yet соотв.
setInterval(function(){
document.querySelector("div").className = arrD[
i = ++i%arrD.length
];
}, 60000);
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 questionAsk a Question
731 491 924 answers to any question