S
S
Shakhrom Mukumov2017-01-24 23:08:59
css
Shakhrom Mukumov, 2017-01-24 23:08:59

How to loop a function in jQuery duration and interval?

Is it possible to loop functions in jQuery.
The task is to add a class to an element, after "N" seconds to remove the previously added class, and so that this process is looped with an interval of "N" seconds. Found setInterval and setTimeout just how to combine it into code, or maybe there are easier / more correct options?

ps I'm completely new to JS/JQuery, please help anyone who can ))) Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-01-24
@leon9208

var N = 5000; // 5 секунд

setInterval(function(){
  $('#targetBlock').toggleClass('className');
}, N);

Пример: https://jsfiddle.net/1Lg01xmu/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question